简体   繁体   English

USING子句PLSQL中的动态参数

[英]Dynamic parameters in USING clause PLSQL

I have a question, I'm building a PLSQL code to execute any procedure or function the dynamic way. 我有一个问题,我正在构建一个PLSQL代码以动态方式执行任何过程或功能。 I'm using a metadata table to know which element sql I'll execute this way. 我正在使用元数据表来了解将以这种方式执行的元素sql。

Process some codes to recover informations to build a similar block: 处理一些代码以恢复信息以构建类似的块:

V_COMMAND := 'BEGIN PROC_EX(:1,:2,:3,:4); END;';

But the problem is in apply the command execute immediate because I need bind variable in clause USING the dynamic way. 但是问题在于应用命令立即执行,因为我需要在子句中使用动态方式绑定变量。 I tried to create a String variable that storage all parameters but when I executed I received a ora error ORA-01008 . 我试图创建一个存储所有参数的String变量,但是执行时收到ora错误ORA-01008

I created a temporary var to storage params: 我创建了一个临时变量来存储参数:

V_PARAMS := 'IN P_TABLE, IN P_WHERE, OUT O_MESSAGE, OUT O_CODE';

where: P_TABLE , P_WHERE , O_MESSAGE and O_CODE are variables declared at begin code. 其中: P_TABLEP_WHEREO_MESSAGEO_CODE是在开始代码处声明的变量。

And I executed the command this way: 我以这种方式执行了命令:

EXECUTE IMMEDIATE V_COMMAND USING V_PARAMS;

Is it possible mapping variable the dynamic way in using clause? 使用子句中动态方式可能映射变量吗?

You are looking for DBMS_SQL 您正在寻找DBMS_SQL

Example of usage that fits your needs: 满足您需求的用法示例:

CREATE OR REPLACE PROCEDURE foo (n NUMBER, square OUT NUMBER) IS
      BEGIN square := n * n; END;/

      CREATE OR REPLACE PROCEDURE bulk_plsql 
         (n DBMS_SQL.NUMBER_TABLE, square OUT DBMS_SQL.NUMBER_TABLE) IS
      c NUMBER;
      r NUMBER;
      BEGIN
        c := DBMS_SQL.OPEN_CURSOR;
        DBMS_SQL.PARSE(c, 'BEGIN foo(:bnd1, :bnd2); END;', DBMS_SQL.NATIVE);
        DBMS_SQL.BIND_ARRAY(c, 'bnd1', n);
        DBMS_SQL.BIND_ARRAY(c, 'bnd2', square);
        r := DBMS_SQL.EXECUTE(c);
        DBMS_SQL.VARIABLE_VALUE(c, 'bnd2', square);
     END;
     /

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM