一般 oracle脚本执行 例子,查询表是否存在等 文件名以.sql结尾

1. 如果表存在,就删除表

a integer;
Begin 
select count(*) into a from user_tables t where TABLE_NAME =upper('表名');
 if a = 1 then
  execute immediate 'drop table 表名';

end if;

2. 如果表不存在,就创建表

a integer;
Begin 
select count(*) into a from user_tables t where TABLE_NAME =upper('表名');
 if a = 0 then
  execute immediate 'create table 表名
(
  guid       VARCHAR2(32) not null,
  columncode VARCHAR2(50),
  columnname VARCHAR2(100),
  datatype   VARCHAR2(3),
  tablecode  VARCHAR2(30),
  ordercode  INTEGER,
  orgin      VARCHAR2(100)
)';

end if;

3,插入信息

begin
delete from GCFR_T_REPCOLUMN_BASICDATA;
insert into 表名(guid, columncode, columnname, datatype, tablecode, ordercode, orgin)
values ('7AEE936E2F2249A0803E28713CEEF510', '区划', '区划', 'S', 'GCFR_V_REPORTGATHER_BM', 1, null);
insert into 表名(guid, columncode, columnname, datatype, tablecode, ordercode, orgin)
values ('2C5C4579BDD74238BDCD732126BE0A10', '地区', '地区', 'S', 'GCFR_V_REPORTGATHER_BM', 2, null);


猜你喜欢

转载自blog.csdn.net/hanzl1/article/details/80776145
今日推荐