此处不允许列oracle SQL insert中的错误
嗨,我在尝试将输入参数插入错误表时遇到此错误此处不允许列oracle SQL insert中的错误,sql,oracle,ora-00947,Sql,Oracle,Ora 00947,嗨,我在尝试将输入参数插入错误表时遇到此错误 CREATE OR REPLACE PROCEDURE consolidate_SI( primary_SI IN NUMBER, secondary_SI IN NUMBER ) IS v_primary_si number; v_secondary_si number; Begin v_primary_si:= primary_si; EXECUTE IMMEDIATE 'insert into error
CREATE OR REPLACE PROCEDURE consolidate_SI(
primary_SI IN NUMBER,
secondary_SI IN NUMBER )
IS
v_primary_si number;
v_secondary_si number;
Begin
v_primary_si:= primary_si;
EXECUTE IMMEDIATE 'insert into error_log ( identifier, error_message) values
(''Successfully updated'',v_primary_si)';
execute immediate 'commit';
End;
我在运行时遇到以下错误
ORA-00984:此处不允许使用列
您不需要动态SQL:
CREATE OR REPLACE PROCEDURE consolidate_SI(primary_SI IN NUMBER, secondary_SI IN NUMBER) IS
v_primary_si NUMBER;
v_secondary_si NUMBER;
BEGIN
v_primary_si := primary_si;
insert into error_log ( identifier, error_message) values ('Successfully updated',v_primary_si);
commit;
END;
此外,问题在于您在动态SQL中引用变量
v\u primary\u si
的方式。您不需要动态SQL:
CREATE OR REPLACE PROCEDURE consolidate_SI(primary_SI IN NUMBER, secondary_SI IN NUMBER) IS
v_primary_si NUMBER;
v_secondary_si NUMBER;
BEGIN
v_primary_si := primary_si;
insert into error_log ( identifier, error_message) values ('Successfully updated',v_primary_si);
commit;
END;
此外,问题在于在动态SQL中引用变量
v_primary_si
的方式。动态SQL上下文不知道v_primary_si
是什么-PL/SQL变量不在该SQL上下文的范围内-因此默认情况下它将其视为列标识符:因此出现错误。要使用PL/SQL变量,可以将其作为绑定变量使用和提供:
EXECUTE IMMEDIATE 'insert into error_log ( identifier, error_message) values
(''Successfully updated'',:v_primary_si)'
USING v_primary_si;
但在这里,提交和提交都不需要是动态的,您只需执行以下操作:
Begin
v_primary_si:= primary_si; -- presumably you need this as a new variable later?
insert into error_log ( identifier, error_message)
values ('Successfully updated', v_primary_si);
commit;
End;
动态SQL上下文不知道什么是
v_primary_si
,PL/SQL变量不在该SQL上下文的范围内,因此默认情况下它将其视为列标识符:因此出现错误。要使用PL/SQL变量,可以将其作为绑定变量使用和提供:
EXECUTE IMMEDIATE 'insert into error_log ( identifier, error_message) values
(''Successfully updated'',:v_primary_si)'
USING v_primary_si;
但在这里,提交和提交都不需要是动态的,您只需执行以下操作:
Begin
v_primary_si:= primary_si; -- presumably you need this as a new variable later?
insert into error_log ( identifier, error_message)
values ('Successfully updated', v_primary_si);
commit;
End;
欢迎来到堆栈溢出。您可以使用工具栏按钮格式化源代码,这次我已经为您完成了。编辑器正下方还有一个预览窗格,以便在发布更改之前查看更改的外观。欢迎使用堆栈溢出。您可以使用工具栏按钮格式化源代码,这次我已经为您完成了。在编辑器的正下方还有一个预览窗格,这样您可以在发布更改之前查看更改的外观。快速简单!谢谢又快又简单!谢谢