Reputation: 17
Hi I am getting this error while trying to insert the INPUT parameter into error table
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;
I am getting the below error at run time
ORA-00984: column not allowed here
Upvotes: 0
Views: 1288
Reputation: 191275
The dynamic SQL context doesn't know what v_primary_si
is - the PL/SQL variables are not in scope inside that SQL context - so it sees it as a column identifier by default: hence the error. To use the PL/SQL variable you would use and supply it as a bind variable:
EXECUTE IMMEDIATE 'insert into error_log ( identifier, error_message) values
(''Successfully updated'',:v_primary_si)'
USING v_primary_si;
But neither that nor the commit need to be dynamic here, you can just do:
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;
Upvotes: 2
Reputation: 22949
You don't need dynamic 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;
Besides, the issue is in the way you reference the variable v_primary_si
in your dynamic SQL.
Upvotes: 3