1. 程式人生 > >oracle建立資料表之前如果存在資料表就刪除,之後建立新資料表

oracle建立資料表之前如果存在資料表就刪除,之後建立新資料表

declare  

i integer;  
begin  
select count(*) into i from user_tables where table_name = 'YY_TEST';  
if i > 0 then  
dbms_output.put_line('該表已存在!');  
execute immediate 'DROP TABLE YY_TEST';  
else  
dbms_output.put_line('該表不存在');  
end if;  
execute immediate 'CREATE TABLE YY_TEST(id int primary key,name varchar(50),username varchar(50))';  
end;