oracle 创建表前判断是否存在

来源:互联网 发布:淮南职业技术学院网络 编辑:程序博客网 时间:2024/05/18 03:54

declare
  tableCount number;
begin
  select count(*)
    into tableCount
    from user_all_tables
   where table_name = upper('test');
  if tableCount = 0 then
    execute immediate 'create table test(ID NUMBER not null,NAME VARCHAR2(30) not null)';
    execute immediate 'insert into test (ID,NAME)values(1,''b'')';
    execute immediate 'insert into test (ID,NAME)values(2,''c'')';
    execute immediate 'insert into test (ID,NAME)values(3,''d'')';
    execute immediate 'insert into test (ID,NAME)values(4,''a'')';
    execute immediate 'commit';
  end if;
end;
/
select * from test;

 update test set name='f' where id=1;

commit;
select * from test;

原创粉丝点击