--parametro de entrada nombre de usuario

set feed off

DECLARE
      v_num number;
      err_num          NUMBER;
      err_msg          VARCHAR2 (255);
BEGIN
	DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA;

	select 1 into v_num from dba_users where username = upper('&1');

	DBMS_RESOURCE_MANAGER_PRIVS.GRANT_SWITCH_CONSUMER_GROUP (
	grantee_name => '&1',
	consumer_group => 'DGA_BAD_APP2',
	grant_option => FALSE);

	DBMS_RESOURCE_MANAGER.SET_INITIAL_CONSUMER_GROUP (user => '&1', consumer_group => 'DGA_BAD_APP2');
	
	DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA;
	
    dbms_output.put_line('Usuario '||upper('&1')||' incluido correctamente en el grupo DGA_BAD_APP2');
EXCEPTION
	WHEN OTHERS THEN
		err_num := SQLCODE;
		err_msg := SQLERRM;
		DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA;
		dbms_output.put_line('Error en la asignacion del usuario '||upper('&1'));
		dbms_output.put_line('Num error:'||err_num);
		dbms_output.put_line('Error:'||err_msg);
END;
/

set feed on
