My MERGE INTO statement works in SQL using SQL Developer:
MERGE INTO EMAIL_LIST d USING (SELECT 'stackoverflowuser95@gmail.com' EMAIL FROM DUAL) s ON (d.EMAIL = s.EMAIL) WHEN NOT MATCHED THEN INSERT (EMAIL) VALUES (s.EMAIL);
But doesn’t work when attempted in PHP:
$update_or_insert_list = oci_parse($conn,
"MERGE INTO EMAIL_LIST d USING (SELECT :email EMAIL FROM DUAL) s ON (d.EMAIL = s.EMAIL) WHEN NOT MATCHED THEN INSERT (EMAIL) VALUES (s.EMAIL);"
); // Also tried with ':email' and/or with ; inside the SQL statement
oci_bind_by_name($update_or_insert_list, ':email', $email);
oci_execute($update_or_insert_list);
Here is the table:
CREATE TABLE EMAIL_LIST (
EMAIL VARCHAR2 (100) NOT NULL
);
ALTER TABLE EMAIL_LIST
ADD CONSTRAINT PK_EMAIL_LIST PRIMARY KEY ( EMAIL ) ;
-- And yes, this is a test-case!
This is not a
MERGEerror, remove the ending;in your query.The final semi-colon is not part of the SQL. It is used in various client interface (SQL*Plus, SQL Developer…) to indicate the end of the SQL statement. In PHP each request is a single SQL statement so the semi-colon is not necessary.