写一个简单的存储过程 create or replace procedure test1 is ls_tab_name varchar2(20); bdgin select tname into ls_tab_name from tab where tname='TEST' if ls_tab_name is not null then drop table test; end if; end test1;
写存储过程吧: DECLARE v_name user_tables.table_name%type; begin select table_name into v_name from user_tables where table_name = 'test'; if v_name is not null then execute immediate 'drop table t1'; end if; exception WHEN NO_DATA_FOUND then dbms_output.put_line('不存在此表'); end;
declare v_count integer; begin Select Count(*) into v_Count from user_Tables where Table_Name='temp' if v_count >0 then drop table temp; end if; end;
原理谁都懂,写出具体的语句好吗? feng1959(血踪万里)
我要的是删除掉一个table的语句,
能给个能执行的吗?
create or replace procedure test1 is
ls_tab_name varchar2(20);
bdgin
select tname into ls_tab_name from tab where tname='TEST'
if ls_tab_name is not null then
drop table test;
end if;
end test1;
DECLARE
v_name user_tables.table_name%type;
begin
select table_name into v_name from user_tables where table_name = 'test';
if v_name is not null then
execute immediate 'drop table t1';
end if;
exception
WHEN NO_DATA_FOUND then
dbms_output.put_line('不存在此表');
end;
begin
Select Count(*) into v_Count from user_Tables where Table_Name='temp'
if v_count >0 then
drop table temp;
end if;
end;
存在你也是要删,不存在删了也没有问题,Oracle还会特别提示你。
我是怕有的数据库突然报错就导致程序终止,
比如mysql,如果不加if exists的话在有的版本上就会有问题,
当然,mssql是可以忽略错误的。oracle,db2,sybase里面可能又有所不一样,
所以为了安全,最好还是先判断一下
因为建表过程非常复杂,所以希望比较简洁
try
//exec drop table sql
except
end;