1 Star 1 Fork 0

汪少棠/material

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
当表不存在时新建表.sql 1.72 KB
一键复制 编辑 原始数据 按行查看 历史
汪少棠 提交于 2024-06-28 10:08 +08:00 . docs: 当表不存在时新建表
declare
v_sql varchar2(32767);--自动执行的 DDL 语句
v_tab_is_exists number := 0;-- 表是否存在
begin
SELECT count(1)
into v_tab_is_exists
FROM user_tables t
where t.TABLE_NAME = upper('SCHEMA_VERSION');
if v_tab_is_exists > 0 then
dbms_output.put_line('表已经存在,不再自动新建.');
else
v_sql := 'create table SCHEMA_VERSION (
id VARCHAR2(38) not null,
version VARCHAR2(200),
description VARCHAR2(1000),
type VARCHAR2(10),
script VARCHAR2(200) not null,
server_name VARCHAR2(200),
update_by VARCHAR2(200),
update_on DATE,
create_time DATE not null)';
execute immediate (v_sql);
dbms_output.put_line('新建表完成.');
v_sql := 'alter table SCHEMA_VERSION add primary key (ID)';
execute immediate (v_sql);
dbms_output.put_line('创建主键完成.');
end if;
end;
/
-- Add comments to the table
comment on table SCHEMA_VERSION is '脚本记录表';
-- Add comments to the columns
comment on column SCHEMA_VERSION.id is '主键';
comment on column SCHEMA_VERSION.version is '版本信息';
comment on column SCHEMA_VERSION.description is '描述信息';
comment on column SCHEMA_VERSION.type is '类型(sql)';
comment on column SCHEMA_VERSION.script is '脚本文件名称';
comment on column SCHEMA_VERSION.server_name is '所属服务(basic、pm、budget、config)';
comment on column SCHEMA_VERSION.update_by is '更新人';
comment on column SCHEMA_VERSION.update_on is '更新时间';
comment on column SCHEMA_VERSION.create_time is '执行时间';
-- Create/Recreate primary, unique and foreign key constraints
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/wangmx1993/material.git
git@gitee.com:wangmx1993/material.git
wangmx1993
material
material
master

搜索帮助