Skip to content

Instantly share code, notes, and snippets.

View stewstryker's full-sized avatar

Stew Stryker stewstryker

  • Dartmouth College
  • Hanover, NH, USA
View GitHub Profile
@stewstryker
stewstryker / Generate Merge statement from target table - ENHANCED.sql
Last active September 2, 2022 03:38
Generate Merge statement from target table definition, With added WHERE clause on UPDATE statement,
-- Generate Merge statement from target table definition
-- Original version by RazorFink: https://gist.github.com/RazorFink/5936619
-- I simply added a WHERE clause on UPDATE statement, so only records w/ changes are updated.
WITH target AS
(SELECT UPPER(TRIM(:owner)) AS owner,
UPPER(TRIM(:table_name)) AS table_name
FROM dual),
all_cols AS
(SELECT atc.owner AS owner,
atc.table_name AS table_name,