解决方法
只需使用RETURNING子句即可.
例如 –
RETURNING identity_id INTO variable_id;
测试用例 –
sql> set serveroutput on sql> CREATE TABLE t 2 (ID NUMBER GENERATED ALWAYS AS IDENTITY,text VARCHAR2(50) 3 ); Table created. sql> sql> DECLARE 2 var_id NUMBER; 3 BEGIN 4 INSERT INTO t 5 (text 6 ) VALUES 7 ('test' 8 ) RETURNING ID INTO var_id; 9 DBMS_OUTPUT.PUT_LINE('ID returned is = '||var_id); 10 END; 11 / ID returned is = 1 PL/sql procedure successfully completed. sql> sql> select * from t; ID TEXT ---------- -------------------------------------------- 1 test sql>