我编写了这个函数来将我的序列的 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;