Pokud používáte Oracle 12c
, pak můžete definovat IDENTITY
sloupec přes GENERATED ALWAYS AS IDENTITY
v definici tabulky a postupujte podle níže uvedeného postupu:
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
Chcete-li resetovat IDENTITY
sloupec (RowNums
), použijte :
SQL> ALTER TABLE tt_temptable MODIFY( RowNums Generated as Identity (START WITH 1));
když se uvolní sdílené zámky na stole.