Python Forum
Oracle Merge using cx_oracle - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Oracle Merge using cx_oracle (/thread-16791.html)



Oracle Merge using cx_oracle - raulp2301 - Mar-15-2019

I am facing an issue with the below Merge statement

cur.execute(('MERGE INTO NETSUITE.NET_TRANSACTION_LINES_EV as Target  '
	         'USING (SELECT  * FROM '
	         '(VALUES vals) '
	         'AS s (TRANSACTION_ID, TRANSACTION_LINE_ID, UNIQUE_KEY) '
	         ') AS Source '
	         'ON Target.UNIQUE_KEY = Source.UNIQUE_KEY '
	         'WHEN NOT MATCHED THEN '
	         'INSERT (TRANSACTION_ID, TRANSACTION_LINE_ID, UNIQUE_KEY) VALUES (Source.TRANSACTION_ID, Source.TRANSACTION_LINE_ID, Source.UNIQUE_KEY) '
	         'WHEN MATCHED THEN '
             'UPDATE SET TRANSACTION_ID=Source.TRANSACTION_ID, TRANSACTION_LINE_ID =Source.TRANSACTION_LINE_ID;'
	         .format( vals = [str(i) for i in records])))
i am passing values on the fly.
My records is has data like this :- [[1,2,3] , [7,8,9], [5,7,8]]
which I am assigning to 'vals = [str(i) for i in records])'.
Also the above code which I found on the internet is the syntax for MySQL and not Oracle. I think I would need to select from dual for the values on the fly