oracle添加字段前先判断字段是否已存在

declare n number;
begin
  select count(1) into n from  all_table_columns where table_name = upper('表名') and column_name = upper('字段名');
  if n = 0 then
  dbms.put_line('字段不存在');
  execute immediate 'alter table 表名 add 字段名 字段类型(长度)';
  if n > 0 then
    dbms_output.put_line('字段已存在');
  end if;
end;
/
 
 
原文地址:https://www.cnblogs.com/xileman/p/11019503.html