日期:2014-05-16  浏览次数:20337 次

存储过程中创建和删除表,并执行表空间
create or replace procedure mytestdrop as
v_cnt  number;
begin
  select count(*) into v_cnt from user_tables where table_name = 'MYTESTDROPTABLE';
  if v_cnt>0
  then
  dbms_output.put_line('该表存在!');
  execute immediate  'drop table MYTESTDROPTABLE';
  end If;
  dbms_output.put_line('不存在就创建表!');
  execute immediate 'create table MYTESTDROPTABLE tablespace MYDB_SPACE as select * from GETSYSDATE';

  select count(*) into v_cnt from user_tables where table_name = 'MYTESTDROPTABLE1';
  if v_cnt>0
  then
  dbms_output.put_line('该表存在!');
  execute immediate  'drop table MYTESTDROPTABLE1';
  end If;
  dbms_output.put_line('不存在就创建表!');
  execute immediate 'create table MYTESTDROPTABLE1 tablespace MYDB_SPACE as select * from GETSYSDATE';
end;