我正在尝试创建一个通用程序来同步序列。
我想调用过程并传递表、列和序列的名称,但由于错误,我的过程无法运行。
程序:
CREATE OR REPLACE PROCEDURE INCREMENT_SEQ(table_name in varchar2 , id_column in varchar2 , sequence_name in varchar2)
AS
current_value number;
seq_val number := -1;
begin
EXECUTE IMMEDIATE 'select max(' || table_name || '.' || id_column || ') into current_value from ' || table_name ;
WHILE current_value >= seq_val
LOOP
EXECUTE IMMEDIATE 'select ' || sequence_name || '.nextval into seq_val from dual';
end loop;
end;
当我运行脚本时,出现以下错误:但我不知道如何解决。任何建议都会有所帮助。
最佳答案
您应该将 INTO
子句放在查询之外:
CREATE OR REPLACE PROCEDURE INCREMENT_SEQ(table_name in varchar2 , id_column in varchar2 , sequence_name in varchar2)
AS
current_value number;
seq_val number := -1;
begin
EXECUTE IMMEDIATE 'select max(' || table_name || '.' || id_column || ') from ' || table_name into current_value;
WHILE current_value >= seq_val
LOOP
EXECUTE IMMEDIATE 'select ' || sequence_name || '.nextval from dual' into seq_val;
end loop;
end;
关于oracle 程序给出 ORA-00905 : missing keyword,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28478190/