Oracle achieves the effect similar to MySQL drop table if exists

Oracle does not have the syntax of drop table if exists. You can use storage to achieve the effect of deleting if the table exists.

-- 定义存储过程
create or replace procedure proc_droptable(
    p_table in varchar2
) is
    v_count number(10);
begin
   select count(*) into v_count from user_tables
   where table_name = upper(p_table);
  
   if v_count > 0 then
      execute immediate 'drop table ' || p_table ||' purge';
   end if;
   
end proc_droptable;   

-- 调用执行过程
exec proc_droptable('tableName');

 

 


[Java interview questions and answers] sorting recommendations

 

Published 562 original articles · praised 1543 · 1.65 million views +

Guess you like

Origin blog.csdn.net/meism5/article/details/105377144