oracle创建表时加判断 ------过程

来源:互联网 发布:php 分页第二页不显示 编辑:程序博客网 时间:2024/06/05 21:49

/**创建表的过程
如果表存在,则删除再创建
否则直接创建
*/
declare 
  tabCount number;
begin
  --查询要创建的表是否存在
  select  count(1) into  tabCount  from user_tables  where  table_name='QUESTION';
 
  --如果存在,则删除该表
  if  tabCount>0  then
      dbms_output.put_line('表或视图不存在!');
      execute   immediate  'drop table  QUESTION';
  end   if;
 
  execute   immediate  'create  table  question(
        id   number  not null primary key,
        title  varchar(180)  not null  ,
        start_date  varchar(28) ,
        end_time   varchar(28)
  )';
 
  tabCount:=0;
 
end;

原创粉丝点击