2

I'm trying to reference my new variable from dynamic sql.

If I try select :NEW.zh_naam into v_var from dual;, and I print out my variable, averything works perfectly.

But when I try to use dynamic sql, like this execute immediate('select :NEW.zh_naam from dual') into v_var, I get an error message ORA-01008: not all variables bound.

Is there any work around for this problem?

1

1 Answer 1

2

execute immediate statements don't share variable scope with the caller. (Also : within the quoted statement indicates a bind variable.) You would have to pass the value in as a bind variable.

execute immediate 'select :b from dual' into v_var using :new.zh_naam;

Update: from the discussion below it seems you want to build the set of :new references dynamically. This is not possible. Instead you might be able to generate the entire trigger dynamically as part of your release process, or else enable the built-in Oracle auditing or Flashback Data Archive.

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for the answer. I suppose I can't make the ':new.zh_naam' variable?
You cannot do that. :new and :old are reserved key words and get the values when some event occurs on the table. When you write it in dynamic query, it means you wanted to use it as a bind variable.
I'm afraid that won't be possible. You could perhaps generate the entire trigger dynamically as part of your release process, or else enable the built-in Oracle auditing or Flashback Data Archive if that's any help.
Do simply v_var := :new.zh_naam;
@WernfriedDomscheit - agreed, if it was just a case of getting the value of :new.zh_naam into v_var that would be the way to do it. Unfortunately he wants the trigger code to figure out all of the :new names dynamically at runtime.
|

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.