{"id":1867,"date":"2013-06-04T03:01:52","date_gmt":"2013-06-04T03:01:52","guid":{"rendered":"http:\/\/www.withdata.com\/ad\/?p=1867"},"modified":"2024-08-17T05:38:56","modified_gmt":"2024-08-17T05:38:56","slug":"replace-update-or-insert-a-row-into-oracle-table-merge-into","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/oracle\/replace-update-or-insert-a-row-into-oracle-table-merge-into.html","title":{"rendered":"Replace (Update\/Insert) a row into Oracle table &#8211; Merge into"},"content":{"rendered":"<p>In Mysql, \u00a0if you want to either updates or inserts a row in a table, depending if the table already has a row that matches the data, you\u00a0can use &#8220;ON DUPLICATE KEY UPDATE&#8221;.<\/p>\n<p>How to do it in Oracle?<\/p>\n<p>Use &#8220;merge into&#8221; .<\/p>\n<pre>MERGE INTO employees USING dual ON ( \"id\"=123456 )\r\nWHEN MATCHED THEN UPDATE SET \"last_name\"=\"smith\" , \"first_name\"=\"bob\"\r\nWHEN NOT MATCHED THEN INSERT (\"id\",\"last_name\",\"first_name\")\r\n    VALUES ( 123456,\"smith\", \"bob\" )<\/pre>\n<p>&nbsp;<\/p>\n<p>See also:<\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/oraloader\/upsert-data-from-csv-file-to-oracle-without-programming.html\"> Upsert data from CSV to Oracle<\/a><br \/>\n<a href=\"http:\/\/www.withdata.com\/blog\/oraloader\/upsert-data-from-tsv-file-to-oracle-without-programming.html\"> Upsert data from TSV to Oracle<\/a><br \/>\n<a href=\"http:\/\/www.withdata.com\/blog\/oraloader\/upsert-data-from-txt-file-to-oracle-without-programming.html\"> Upsert data from TXT to Oracle<\/a><br \/>\n<a href=\"http:\/\/www.withdata.com\/blog\/xlstoora\/upsert-data-from-excel-file-to-oracle-without-programming.html\"> Upsert data from Excel to Oracle<\/a><br \/>\n<a href=\"http:\/\/www.withdata.com\/blog\/xmltooracle\/upsert-data-from-xml-file-to-oracle-without-programming.html\"> Upsert data from XML to Oracle<\/a><br \/>\n<a href=\"http:\/\/www.withdata.com\/blog\/jsontooracle\/upsert-data-from-json-file-to-oracle-without-programming.html\"> Upsert data from JSON to Oracle<\/a><br \/>\n<a href=\"http:\/\/www.withdata.com\/blog\/sqltooracle\/upsert-data-from-sql-file-to-oracle-without-programming.html\"> Upsert data from SQL file to Oracle<\/a><\/p>\n<p>Replace (Update\/Insert) a row into other DB:<\/p>\n<p>In SQL Server,\u00a0<a href=\"https:\/\/www.withdata.com\/blog\/sql-server\/replace-update-or-insert-a-row-into-sql-server-table.html\">https:\/\/www.withdata.com\/blog\/sql-server\/replace-update-or-insert-a-row-into-sql-server-table.html<\/a>\u00a0.<\/p>\n<p>In DB2,\u00a0<a href=\"https:\/\/www.withdata.com\/blog\/db2\/replace-update-or-insert-a-row-into-db2-table-merge-into.html\">https:\/\/www.withdata.com\/blog\/db2\/replace-update-or-insert-a-row-into-db2-table-merge-into.html<\/a>\u00a0.<\/p>\n<p>In PostgreSQL,\u00a0<a href=\"https:\/\/www.withdata.com\/blog\/postgresql\/replace-update-or-insert-a-row-into-postgresql-table.html\">https:\/\/www.withdata.com\/blog\/postgresql\/replace-update-or-insert-a-row-into-postgresql-table.html<\/a><\/p>\n<p>In Sqlite,\u00a0<a href=\"https:\/\/www.withdata.com\/blog\/sqlite\/replace-update-or-insert-a-row-into-sqlite-table.html\">https:\/\/www.withdata.com\/blog\/sqlite\/replace-update-or-insert-a-row-into-sqlite-table.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Mysql, \u00a0if you want to either updates or inserts a row in a table, depending if the table already has a row that matches the data, you\u00a0can use &#8220;ON DUPLICATE KEY UPDATE&#8221;. How to do it in Oracle? Use &#8220;merge into&#8221; . MERGE INTO employees USING dual ON ( &#8220;id&#8221;=123456 ) WHEN MATCHED THEN [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[238,1325,239,428],"class_list":["post-1867","post","type-post","status-publish","format-standard","hentry","category-oracle","tag-merge-into","tag-oracle","tag-replace-into","tag-upsert"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/1867","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/comments?post=1867"}],"version-history":[{"count":13,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/1867\/revisions"}],"predecessor-version":[{"id":21732,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/1867\/revisions\/21732"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=1867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=1867"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=1867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}