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;
/
 
 
posted @ 2019-06-13 21:11  希乐曼  阅读(3707)  评论(0编辑  收藏  举报