Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple updates in execute immediate

I have a couple of update statements that I have to execute dynamically . I am executing both these update statements using execute immediate. However, I get the following error when I do so :

ORA-00911: invalid character
ORA-06512: at line 7
00911. 00000 -  "invalid character"
*Cause:    identifiers may not start with any ASCII character other than ..

Is there a limitation that one cannot execute more than 1 update statement in Execute immediate ?

Edit: With example:

begin 
EXECUTE IMMEDIATE 'UPDATE tt_TGT_TABLE SET PK_1 = ''Demand10'' where ROW_ID = 3923866 ; UPDATE tt_TGT_TABLE SET PK_1 = ''Demand11'' where ROW_ID = 3923868'; 
end;
like image 360
shirjai Avatar asked Sep 24 '15 09:09

shirjai


People also ask

What is true about execute immediate statement?

The EXECUTE IMMEDIATE statement executes a dynamic SQL statement or anonymous PL/SQL block. You can use it to issue SQL statements that cannot be represented directly in PL/SQL, or to build up statements where you do not know all the table names, WHERE clauses, and so on in advance.

How do you use bulk collect in execute immediate in Oracle?

You can use the RETURNING BULK COLLECT INTO clause with the EXECUTE IMMEDIATE statement to store the results of an INSERT , UPDATE , or DELETE statement in a set of collections. You can use the BULK COLLECT INTO clause with the FETCH statement to store values from each column of a cursor in a separate collection.


1 Answers

You cannot simply concatenate multiple statements within an EXECUTE IMMEDIATE call - you'll either have to use several calls:

begin 
  EXECUTE IMMEDIATE 'UPDATE tt_TGT_TABLE SET PK_1 = ''Demand10'' where ROW_ID = 3923866';
  EXECUTE IMMEDIATE 'UPDATE tt_TGT_TABLE SET PK_1 = ''Demand11'' where ROW_ID = 3923868'; 
end;

or feed an anonymous PL/SQL block into EXECUTE IMMEDIATE:

begin 
  EXECUTE IMMEDIATE '
    begin
      UPDATE tt_TGT_TABLE SET PK_1 = ''Demand10'' where ROW_ID = 3923866;
      UPDATE tt_TGT_TABLE SET PK_1 = ''Demand11'' where ROW_ID = 3923868;
    end;';   
end;
like image 136
Frank Schmitt Avatar answered Sep 23 '22 00:09

Frank Schmitt