set serveroutput on ;
set define off;
set feedback off;
--
--
--
exec dbms_output.put_line ('======================================');
exec dbms_output.put_line ('q02b_pre_0002_bis.sql: INICIO DE EJECUCION');
exec dbms_output.put_line ('======================================');
--
--
--
exec dbms_output.put_line ('==================');
exec dbms_output.put_line ('ACTUALIZA SECUENCIA USUARIOS');
exec dbms_output.put_line ('==================');
DECLARE
    max_id number(8):=0;
begin
EXECUTE IMMEDIATE 'SELECT MAX(q022ft00_idusuario) FROM q022ft00' INTO max_id;  
    
EXECUTE IMMEDIATE 'DROP SEQUENCE Q022FQ00';
commit; 

EXECUTE IMMEDIATE '
  CREATE SEQUENCE Q022FQ00
  START WITH ' ||  (NVL(max_id,0) + 1) || '
  MAXVALUE 999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  NOCACHE
  NOORDER';

EXECUTE IMMEDIATE 'GRANT SELECT ON  Q02B.Q022FQ00 TO Q02A';

commit;    
end;
/
exec dbms_output.put_line ('===================================');
exec dbms_output.put_line ('q02b_pre_0002_bis.sql: FIN DE EJECUCION');
exec dbms_output.put_line ('===================================');
set serveroutput off;
commit;
exit;