0

I am using the first time the command EXECUTE IMMEDIATE and I like to ask if you can help me.

I have a variable column, because of that I search on the internet and found the EXECUTION IMMEDIATE command but it gives me the following Error:

ORA-00904: "ACTUATION": invalid identifier
ORA-06512: at line 9

I am really confused, because ACTUATION is the "old_val" column and not the "column_name" column maybe you can help me. Here is the code:

declare
cursor such is 
select column_name, old_val, CTN.ID from abc.firsttable
ctn, def.secondtable#CC ctncc
where CTN.bup#rev = CTNCC.bup#rev
and ID in (127605689)
and CTN.bup#changefrom > to_date ('08/06/2017', 'dd/MM/YYYY');
begin
for srec in such loop 
EXECUTE IMMEDIATE
'update firsttable ctn2
set ctn.' || srec.column_name || ' = '|| srec.old_val ||' 
where CTN2.ID = '|| srec.id;
end loop; 
end;
1
  • 2
    Construct the SQL query and print it out. 95% of the time, the error is obvious. Commented Jun 13, 2017 at 11:54

2 Answers 2

4

Try this one:

EXECUTE IMMEDIATE
   'update firsttable ctn2
    set ctn.' || srec.column_name || ' = :OldVal 
    where CTN2.ID = :id' 
using srec.old_val, srec.id;
Sign up to request clarification or add additional context in comments.

1 Comment

This is better than the accepted answer, in terms of performance and scalability.
2

i think so, you must add more ' between params of string:

show this, in your code i added 3 ' between || srec.old_val ||

EXECUTE IMMEDIATE
'update firsttable ctn2
set ctn.' || srec.column_name || ' = '''|| srec.old_val ||'''
where CTN2.ID = '|| srec.id;
end loop; 
end;

2 Comments

Thank you! Sometimes it is so simple you can't see the problem.
Note, this will fail for values like don't quote it like this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.