Advertisement
dwhitzzz

Add column if not exists

May 8th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.54 KB | None | 0 0
  1. DECLARE v_column_exists NUMBER := 0;
  2. BEGIN
  3. SELECT COUNT(*) INTO v_column_exists FROM all_tab_cols WHERE column_name = 'columnName' AND TABLE_NAME = 'PGBORDEREAU';
  4. IF (v_column_exists = 0) THEN EXECUTE IMMEDIATE 'your sql to add a column';
  5. END IF;
  6. END;
  7. /
  8.  
  9. e.g.
  10.  
  11.  
  12. DECLARE v_column_exists NUMBER := 0;
  13. BEGIN
  14. SELECT COUNT(*) INTO v_column_exists FROM all_tab_cols WHERE column_name = 'EMPCODE ' AND TABLE_NAME = 'EMPLOYEE ';
  15. IF (v_column_exists = 0) THEN EXECUTE IMMEDIATE 'ALTER TABLE EMPLOYEE ADD EMPCODE NUMBER(5) DEFAULT 0';
  16. END IF;
  17. END;
  18. /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement