在Oracle中若删除表中一个不存在的字段,如 “alter table test drop column xxx”,则会提示:
ORA-00904:”xxx”:标识符无效
若在程序中执行该语句则会报异常,这就需要我们在删除字段前先判断该字段是否存在,若存在则删除.
DECLARE 
  num NUMBER; 
BEGIN 
  SELECT COUNT(1) 
    INTO num 
    from cols 
   where table_name = upper('tableName') 
     and column_name = upper('columnName'); 
  IF num > 0 THEN 
      execute immediate 'alter table tableName drop column columnName'; 
  END IF; 
END;
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/bigdata/4101.html