Jika Anda menggunakan Oracle 12c
, maka Anda dapat menentukan IDENTITY
kolom melalui GENERATED ALWAYS AS IDENTITY
dalam definisi tabel Anda dan ikuti cara di bawah ini :
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
Untuk menyetel ulang IDENTITY
kolom (RowNums
), gunakan :
SQL> ALTER TABLE tt_temptable MODIFY( RowNums Generated as Identity (START WITH 1));
setiap kali kunci bersama di atas meja dilepaskan.