Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Como posso redefinir todas as sequências no meu banco de dados Oracle para o valor 0?


Você não precisa de 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;
/

Exemplo (estou usando USER_SEQUENCES em vez de):
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>