Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP oci_execute for Multiple Statements

I'm trying to issue multiple INSERT statements within a single oci_execute() call on PHP. The problem is that I get this error:

ORA-00911: invalid character

I'm guessing it's the ; after each statement.

So now, my question is how do I make multiple INSERT statements that would work within oci_execute()?

Here's my query so far:

INSERT INTO tbl (id, name) VALUES(1, 'John');
INSERT INTO tbl (id, name) VALUES(2, 'Martha');
INSERT INTO tbl (id, name) VALUES(3, 'Richard')

EDIT:

Note that there is no ; at the end of my query because I'm using SQL statements.

like image 841
Patrick Gregorio Avatar asked Oct 18 '25 05:10

Patrick Gregorio


1 Answers

Just wrap all statement into anonymous PL/SQL block:

BEGIN
    INSERT INTO tbl (id, name) VALUES(1, 'John');
    INSERT INTO tbl (id, name) VALUES(2, 'Martha');
    INSERT INTO tbl (id, name) VALUES(3, 'Richard');    
END;

Oracle doesn't support batch of commands. Anonymous PL/SQL block is executed as single command.

like image 190
Husqvik Avatar answered Oct 19 '25 20:10

Husqvik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!