日期:2014-05-17  浏览次数:20904 次

◆◆◆请一类似SQLServer 语句IF exists 的Oracle写法
SQL code
IF exists(SELECT NAME FROM sysobjects WHERE NAME = 'LoginCheck' AND type = 'p')
DROP PROCEDURE LoginCheck

//上面是微软的SQL写法,判断一个对象是否存在,如存在则删除,请问Oracle有没有同样功能的语句,麻烦达人指点

------解决方案--------------------
SQL code
declare
 i int;
begin
  select count(*) into i from user_objects where object_name=upper('LoginCheck') and object_Type=upper('procedure');
  if i>0 then
    execute immediate 'DROP PROCEDURE LoginCheck';
  end if;
end;

------解决方案--------------------
begin
for i in (select null from user_objects where object_name=upper('LoginCheck') and object_Type=upper('procedure')) loop
execute immediate 'DROP PROCEDURE LoginCheck';
end loop;

end;