この関数を作成して、シーケンスの currval を最大 ID+1 に設定しました。しかし、次のようなエラーが発生します。
ORA-14552: cannot perform a DDL, commit or rollback inside a query or DML
その問題を解決するのを手伝ってください。
CREATE OR REPLACE Function createcurrentid (
model_in IN varchar2,
primarykey_in IN VARCHAR2,
seq_name IN VARCHAR2)
RETURN number
IS
cnumber number;
c2 sys_refcursor;
c3 sys_refcursor;
c6 sys_refcursor;
c7 sys_refcursor;
c8 sys_refcursor;
c9 sys_refcursor;
c4 number;
c5 number;
type result_rec is record (
id number,
currvalvalue number
);
l_result_rec result_rec;
BEGIN
open c2 FOR 'SELECT max('||primarykey_in||') AS id FROM '||model_in;
fetch c2 into c4;
close c2;
open c3 FOR 'select '||seq_name||'.currval AS currvalvalue from dual';
fetch c3 into c5;
close c3;
cnumber:=c4-c5;
open c6 FOR 'alter sequence'||seq_name||' increment BY'||cnumber;
commit;
open c8 FOR 'select '||seq_name||'.nextval from dual';
commit;
open c9 FOR 'select '||seq_name||'.CURRVAL from dual';
commit;
open c7 FOR 'alter sequence'||seq_name||' increment BY 1';
commit;
RETURN cnumber;
END;