Se você usa o
Oracle 12c
, então você pode definir uma IDENTITY
coluna através de GENERATED ALWAYS AS IDENTITY
na definição da sua tabela e siga o caminho abaixo:SQL> CREATE GLOBAL TEMPORARY TABLE tt_temptable(
2 RowNums NUMBER(3,0) GENERATED ALWAYS AS IDENTITY,
3 procNums NUMBER(18,0)
4 ) ON COMMIT PRESERVE ROWS;
Table created
SQL>
SQL> DECLARE
2 inputString VARCHAR2(50) := '12,13,14,15';
3 BEGIN
4 INSERT INTO tt_temptable(procNums)
5 SELECT REGEXP_SUBSTR (inputString,'[^,]+',1,LEVEL) ProcNums
6 FROM dual
7 CONNECT BY REGEXP_SUBSTR (inputString,'[^,]+',1,LEVEL) IS NOT NULL;
8 END;
9 /
PL/SQL procedure successfully completed
SQL> SELECT * FROM tt_temptable;
ROWNUMS PROCNUMS
------- -------------------
1 12
2 13
3 14
4 15
Para redefinir a
IDENTITY
coluna (RowNums
), usar :SQL> ALTER TABLE tt_temptable MODIFY( RowNums Generated as Identity (START WITH 1));
sempre que os bloqueios compartilhados na tabela forem liberados.