Reusing Bind Variables in Dynamic PL/SQL : Dynamic SQL « PL SQL Statements « Oracle PL/SQL Tutorial






SQL>
SQL>
SQL> declare
  2      a NUMBER:=2;
  3      b NUMBER:=3;
  4      v_plsql_tx VARCHAR2(2000);
  5  begin
  6      v_plsql_tx := 'BEGIN ' || ' :1 := :1 + :2; ' || 'END;';
  7      execute immediate v_plsql_tx
  8      using in out a, b;
  9      DBMS_OUTPUT.put_line('a='||a);
 10  end;
 11  /
a=5

PL/SQL procedure successfully completed.

In dynamic PL/SQL blocks, Oracle counts only unique bind variables and associates them with arguments in the order of their appearance.









22.15.Dynamic SQL
22.15.1.Building DDL on the Fly
22.15.2.Building SQL on the Fly
22.15.3.Implicit COMMITS in DDL Statements
22.15.4.Using Quoted Strings with Dynamic SQL
22.15.5.Using Bind Variables in Dynamic SQL
22.15.6.Reusing Bind Variables in Dynamic PL/SQL