oracle创建表之前判断表是否存在,如果存在则删除已有表

2025-03-22 23:07:22
推荐回答(1个)
回答1:

写个匿名块就行了,例子:

SQL> create table test(a number);
Table created
SQL> 
SQL> declare
  2  v_count number;
  3  begin
  4   select count(1) into v_count from user_tables t where t.TABLE_NAME='TEST';
  5  if v_count>0 then
  6   execute immediate'drop table TEST';
  7  end if;
  8  execute immediate 'create table test(b number)';
  9  end;
 10  /
PL/SQL procedure successfully completed
SQL> select * from test;
         B
----------