我想在 oracle pl/sql 语句中执行动态代码。
有效的是:
execute immediate 'begin :r := 3*7*(:aa); end;' using in out myresvar,100;
现在我想更概括地说:
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;
不幸的是,这会导致错误,例如(德语):
...事务中的错误:ORA-06536:IN-Bind-Variable an OUT-Position gebunden ...
即执行立即语句的输入和输出变量似乎存在混淆。
现在我很困惑是什么问题。
谁能帮我?