Tuesday, 20 November 2012

Alter table if column doesn't exist (Avoid ORA-01430)

Avoid ORA-01430: column being added already exists
use user_tab_columns (depending on rights)
  
 
declare p_count NUMBER;

select count(1) int p_count
from ALL_TAB_COLUMNS 
where OWNER = '<SCHEMA_NAME>' 
and TABLE_NAME = '<TABLE_NAME>' 
and COLUMN_NAME = '<COLUMN_NAME>';

IF p_count = 0 THEN
    --add your column
END IF;

No comments:

Post a Comment