SET VER OFF;
set feed off;
set echo off;
set timi off;
set serveroutput on;


DECLARE

V_PROPIETARIO VARCHAR2(30):= UPPER('&1');
V_USUARIO VARCHAR2(30) := UPPER('&2');

V_ERRM VARCHAR2(64);
   
BEGIN


FOR CONCESION IN (
   SELECT 'GRANT  '||DECODE (
   OBJECT_TYPE,
   'PACKAGE','EXECUTE',
   'PROCEDURE','EXECUTE',
   'FUNCTION','EXECUTE',
   'SEQUENCE','SELECT',
   'VIEW','SELECT',
   'SELECT,INSERT,DELETE,UPDATE'
   )
   ||' ON '||OWNER||'.'||OBJECT_NAME||' TO '||V_USUARIO PERMISO
   FROM DBA_OBJECTS
   WHERE OWNER = V_PROPIETARIO
   AND OBJECT_TYPE IN ('PROCEDURE','FUNCTION','PACKAGE','SEQUENCE','TABLE','VIEW')
   ORDER BY OBJECT_TYPE)
LOOP
   
   BEGIN

	dbms_output.put_line (CONCESION.PERMISO||';');
	execute immediate (CONCESION.PERMISO);
   
      EXCEPTION WHEN OTHERS THEN
         V_ERRM := SUBSTR(SQLERRM, 1 , 64);
	 DBMS_OUTPUT.PUT_LINE ('ERROR EN :'||CONCESION.PERMISO||' ('||V_ERRM||')');
      
   END;

END LOOP;

END;
/
