2 Replies Latest reply on Nov 13, 2012 10:41 AM by Purvesh K

    Execute Immediate, Update and Bind Variables

    925144
      I can't make EXECUTE IMMEDIATE to work with an update statement while trying to bind the table name. Consider the following example:
      create table gr_test(
        n Number);
        
      insert into gr_test (n) values(1);
      The anonymous block below works:
      declare
        update_statement Varchar2(2000);
      begin
        update_statement := '
        update gr_test
           set n = 2';
      
        execute immediate update_statement;
      end;
      but not
      declare
        update_statement Varchar2(2000);
      begin
        update_statement := '
        update :table_name
           set n = 2';
           
        execute immediate update_statement
          using 'gr_test';
      end;
      It gives ORA-00903 --- Invalid table name.