Skip to content

Instantly share code, notes, and snippets.

@clofresh
Created December 14, 2009 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clofresh/256211 to your computer and use it in GitHub Desktop.
Save clofresh/256211 to your computer and use it in GitHub Desktop.
-- I want my code to be backwards compatible with database versions
SELECT COUNT(*)
INTO has_new_col
FROM all_tab_cols
WHERE table_name = 'UPDATED_TABLE'
AND column_name = 'NEW_COL';
IF has_new_col = 0 THEN
INSERT INTO other_table
(
other_table_sid,
old_col
)
SELECT other_table_sid,
old_old
FROM updated_table;
ELSE
INSERT INTO other_table
(
other_table_sid,
old_col,
new_col
)
SELECT other_table_sid,
old_col,
new_col -- Gives PL/SQL: ORA-00904: "NEW_COL": invalid identifier :(
FROM updated_table;
END IF;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment