Python Forum
MERGE SQL in oracle executemany
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MERGE SQL in oracle executemany
#1
Hi there,

I'm looking to insert values into an oracle table (my_table) using the query below. The insert query works when the PROJECT is not NULL/empty (""). However when PROJECT is an empty string(''), the query creates a new duplicate row every time the code is executed (with project value populating as null). I would like to modify my query so a new row is not inserted when all column values are matched (including when project code is null). Would like guidance with this, thanks.
con = cx_Oracle.connect(connstr)
cur = con.cursor()
rows = [tuple(x) for x in df.values]
cur3.executemany('''merge into my_table
using dual
on (YEAR = :1 and QUARTER = :2 and CODE = :3 and AMOUNT = :4 and DATE = :5 and COMMENTS = :6 and PROJECT = :7)
when not matched then insert values (:1, :2, :3, :4, :5, :6, :7)
''',rows)
con.commit()
cur.close()
con.close()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Command error - cursor.executemany(comandoSQL,valoresInserir) TecInfo 2 1,303 Nov-18-2022, 01:57 PM
Last Post: TecInfo
  Using executemany to import the data Sandy7771989 1 2,642 Jun-11-2019, 07:45 AM
Last Post: Sandy7771989
  MySQL executemany - Failed executing the operation; Could not process parameters josh_marchant 1 7,967 May-16-2019, 04:22 PM
Last Post: woooee
  Read CSV file into MySQL and use executemany instead of execute bluethundr 1 4,164 May-04-2019, 07:35 AM
Last Post: MvGulik
  Validating information from .csv file before executemany mzmingle 7 4,356 Apr-15-2019, 01:40 PM
Last Post: mzmingle
  Problem with pyodbc executemany() RBeck22 1 7,322 Apr-02-2019, 06:12 PM
Last Post: micseydel
  PyODBC error - second parameter to executemany must be a sequence, iterator, or gener RBeck22 1 7,020 Mar-29-2019, 06:44 PM
Last Post: RBeck22
  Oracle Merge using cx_oracle raulp2301 0 4,735 Mar-15-2019, 12:56 AM
Last Post: raulp2301

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020