sql脚本书写规范

一些增量脚本的书写规范,mark一下,这些都是经常用到的

比如:

pdm_table_表名_日期(扩充表字段长度).sql

--修改人
--扩充字段长度
--修改原因

declare
  nCount integer;
begin
  select count(*) into nCount from user_tab_cols where lower(table_name)='表名' and lower(column_name)='列名';
  if nCount=0 then
    execute immediate 'alter table 表名 add 列名 字段类型(长度)';
  end if;
  select count(*) into nCount from user_tab_cols where lower(table_name)='表名' and lower(column_name)='列名';
  if nCount=1 then
    execute immediate 'alter table 表名 modify 列名  字段类型(长度)';
  end if;
end;
/
pdm_table_表名_日期(增加表字段).sql

--修改人
--列名  中文注释 (C_ISCUSTCARD  是否会员)
--增加原因
declare
  icount  integer:=0;
  begin
    select count(1) into icount from user_tab_columns u where lower(u.TABLE_NAME) = '表名' and lower(u.COLUMN_NAME) = '列名';
    if icount = 0 then
      execute immediate 'alter table 表名 add 列名 字段类型(长度)';
    end if;
  end;
/

--增加表字段时填充默认值
declare
  icount  integer:=0;
  begin
    select count(1) into icount from user_tab_columns u where lower(u.TABLE_NAME) = '表名' and lower(u.COLUMN_NAME) = '列名';
    if icount = 0 then
      execute immediate 'alter table 表名 add 列名 字段类型(长度) default ''0''';
    end if;
  end;
/

pdm_table_存储过程名称_日期(删除或增加存储过程).sql

declare
  v_count pls_integer :=0;
begin
    select count(1) into iCount from USER_PROCEDURES t where t.OBJECT_NAME =upper('存储过程名称');
  if iCount = 1 then
    execute immediate 'DROP PROCEDURE 存储过程名称';
  end if;
end;
/

等等吧,反正就是一些可以重复执行的批量脚本

猜你喜欢

转载自beee.iteye.com/blog/2106218
今日推荐