sql >> Base de Datos >  >> RDS >> Oracle

¿Cómo puedo restablecer todas las secuencias en mi Oracle DB al valor 0?

No necesita SQL dinámico.

begin
for i in (select sequence_name from dba_sequences where sequence_name like '%SEQ_PR%') LOOP
  reset_seq(i.sequence_name);           --> this is just fine
end loop;
end;
/

Ejemplo (estoy usando USER_SEQUENCES en su lugar):

SQL> select seq_pr1.nextval from dual;

   NEXTVAL
----------
         9

SQL> select seq_pr2.nextval from dual;

   NEXTVAL
----------
         8

SQL> begin
  2  for i in (select sequence_name from user_sequences where sequence_name like '%SEQ_PR%') LOOP
  3    reset_seq(i.sequence_name);
  4  end loop;
  5  end;
  6  /

PL/SQL procedure successfully completed.

SQL> select seq_pr1.nextval from dual;

   NEXTVAL
----------
         1

SQL> select seq_pr2.nextval from dual;

   NEXTVAL
----------
         1

SQL>