I want to execute dynamic code in an oracle pl/sql statement.
What works good is:
execute immediate 'begin :r := 3*7*(:aa); end;' using in out myresvar,100;
Now I want to do it more generalized:
DECLARE
-- arbitrary formula to evaluate
formula VARCHAR2(100) := 'c+si/2.+mn/6.';
-- string variable to keep pl/sql-code
dynCall VARCHAR2(2046);
-- variables to put into formula evaluation
c NUMBER := 0.02;
si NUMBER := 0.35;
mn NUMBER := 1.5;
res NUMBER;
BEGIN
dynCall := dynCall || 'DECLARE' || chr(10);
dynCall := dynCall || ' c NUMBER;' || chr(10);
dynCall := dynCall || ' si NUMBER;' || chr(10);
dynCall := dynCall || ' mn NUMBER;' || chr(10);
dynCall := dynCall || ' res NUMBER;' || chr(10);
dynCall := dynCall || 'BEGIN' || chr(10);
dynCall := dynCall || ' c := (:aa);' || chr(10);
dynCall := dynCall || ' si := (:bb);' || chr(10);
dynCall := dynCall || ' mn := (:cc);' || chr(10);
dynCall := dynCall || ' :r := ' || formula || ';' || chr(10);
dynCall := dynCall || 'END;' || chr(10);
EXECUTE IMMEDIATE dynCall USING IN OUT c,si,mn,res;
END;
Unfortunately this causes an error like (in german):
... Error in transaction: ORA-06536: IN-Bind-Variable an OUT-Position gebunden ...
i.e. there seems to be a confusion with in and output valiables for the execute immediate statement.
Now I'm confused about what is the problem.
Can anyone help me?