连维良后台,李佳归来,盛夏晚晴天莱雪
在oracle中若删除一个不存在的表,如 “drop table tablename”,则会提示:
ora-00942:表或视图不存在
若在程序中执行该语句则会报异常,这就需要我们在删除表前先判断该表是否存在,若存在则删除.
declare num number; begin select count(1) into num from user_tables where table_name = upper('tablename'); if num > 0 then execute immediate 'drop table tablename'; end if; end;
在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;
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Oracle字符串函数length、upper、lower、initcap、 concat、instr、replace
网友评论