|
|
@@ -0,0 +1,252 @@
|
|
|
+whenever sqlerror exit failure
|
|
|
+set serveroutput on
|
|
|
+
|
|
|
+declare
|
|
|
+ v_count number;
|
|
|
+ procedure create_table_if_missing(p_name varchar2, p_ddl varchar2) is
|
|
|
+ begin
|
|
|
+ select count(*) into v_count from user_tables where table_name = p_name;
|
|
|
+ if v_count = 0 then
|
|
|
+ execute immediate p_ddl;
|
|
|
+ end if;
|
|
|
+ end;
|
|
|
+ procedure create_sequence_if_missing(p_name varchar2, p_ddl varchar2) is
|
|
|
+ begin
|
|
|
+ select count(*) into v_count from user_sequences where sequence_name = p_name;
|
|
|
+ if v_count = 0 then
|
|
|
+ execute immediate p_ddl;
|
|
|
+ end if;
|
|
|
+ end;
|
|
|
+ procedure add_column_if_missing(p_table varchar2, p_column varchar2, p_ddl varchar2) is
|
|
|
+ begin
|
|
|
+ select count(*) into v_count from user_tab_columns
|
|
|
+ where table_name = p_table and column_name = p_column;
|
|
|
+ if v_count = 0 then
|
|
|
+ execute immediate p_ddl;
|
|
|
+ end if;
|
|
|
+ end;
|
|
|
+ procedure add_constraint_if_missing(p_table varchar2, p_name varchar2, p_ddl varchar2) is
|
|
|
+ begin
|
|
|
+ select count(*) into v_count from user_constraints
|
|
|
+ where table_name = p_table and constraint_name = p_name;
|
|
|
+ if v_count = 0 then
|
|
|
+ execute immediate p_ddl;
|
|
|
+ end if;
|
|
|
+ end;
|
|
|
+begin
|
|
|
+ select count(*) into v_count from user_tables
|
|
|
+ where table_name = 'PMS_PROD_20261029_WJJL';
|
|
|
+ if v_count = 0 then
|
|
|
+ execute immediate 'create table PMS_PROD_20261029_WJJL as
|
|
|
+ select w.*, systimestamp bak_time from WJJL w';
|
|
|
+ end if;
|
|
|
+
|
|
|
+ create_table_if_missing('WJLB', 'create table WJLB (
|
|
|
+ WJLBM number(9) not null,
|
|
|
+ MC varchar2(48 char) not null,
|
|
|
+ BJKF number(6,2) default 0 not null,
|
|
|
+ constraint PK_WJLB primary key (WJLBM)
|
|
|
+ )');
|
|
|
+
|
|
|
+ create_table_if_missing('WJLX', 'create table WJLX (
|
|
|
+ WJLXM number(9) not null,
|
|
|
+ MC varchar2(16 char) not null,
|
|
|
+ constraint PK_WJLX primary key (WJLXM)
|
|
|
+ )');
|
|
|
+
|
|
|
+ create_table_if_missing('CSWSJCXM', 'create table CSWSJCXM (
|
|
|
+ CSWSJCXMM number(9) not null,
|
|
|
+ MC varchar2(144 char) not null,
|
|
|
+ MFZ number(9) default 0 not null,
|
|
|
+ ZXZ number(9) default 0 not null,
|
|
|
+ constraint PK_CSWSJCXM primary key (CSWSJCXMM)
|
|
|
+ )');
|
|
|
+
|
|
|
+ create_table_if_missing('CSWSJC', 'create table CSWSJC (
|
|
|
+ CSWSJCID number(16) not null,
|
|
|
+ BJID number(16) not null,
|
|
|
+ JZWID number(16),
|
|
|
+ CDID number(16),
|
|
|
+ JCRYID number(16) not null,
|
|
|
+ FS number(9) default 0 not null,
|
|
|
+ MS varchar2(2048 char),
|
|
|
+ MSWJ varchar2(255 char),
|
|
|
+ FJID number(16),
|
|
|
+ JCSJ timestamp(6) not null,
|
|
|
+ JLZTM number(9) default 1 not null,
|
|
|
+ CJRYID number(16),
|
|
|
+ GLRYID number(16),
|
|
|
+ GLBMID number(16),
|
|
|
+ constraint PK_CSWSJC primary key (CSWSJCID),
|
|
|
+ constraint FK_BJ_CSWSJC foreign key (BJID) references BJ(BJID),
|
|
|
+ constraint FK_CD_CSWSJC foreign key (CDID) references CD(CDID),
|
|
|
+ constraint FK_JZW_CSWSJC foreign key (JZWID) references JZW(JZWID),
|
|
|
+ constraint FK_RY_CSWSJC_JC foreign key (JCRYID) references RY(RYID),
|
|
|
+ constraint FK_JLZT_CSWSJC_JLZTM foreign key (JLZTM) references JLZT(JLZTM),
|
|
|
+ constraint FK_RY_CSWSJC_CJRYID foreign key (CJRYID) references RY(RYID),
|
|
|
+ constraint FK_RY_CSWSJC_GLRYID foreign key (GLRYID) references RY(RYID),
|
|
|
+ constraint FK_BM_CSWSJC_GLBMID foreign key (GLBMID) references BM(BMID)
|
|
|
+ )');
|
|
|
+
|
|
|
+ create_table_if_missing('CSWSJCMX', 'create table CSWSJCMX (
|
|
|
+ CSWSJCMXID number(16) not null,
|
|
|
+ CSWSJCXMM number(9) not null,
|
|
|
+ CSWSJCID number(16) not null,
|
|
|
+ FS number(9) default 0 not null,
|
|
|
+ JLZTM number(9) default 1 not null,
|
|
|
+ CJRYID number(16),
|
|
|
+ GLRYID number(16),
|
|
|
+ GLBMID number(16),
|
|
|
+ constraint PK_CSWSJCMX primary key (CSWSJCMXID),
|
|
|
+ constraint FK_CSWSJCXM_CSWSJCMX foreign key (CSWSJCXMM) references CSWSJCXM(CSWSJCXMM),
|
|
|
+ constraint FK_SSNWJC_CSWSJCMX foreign key (CSWSJCID) references CSWSJC(CSWSJCID),
|
|
|
+ constraint FK_JLZT_CSWSJCMX_JLZTM foreign key (JLZTM) references JLZT(JLZTM),
|
|
|
+ constraint FK_RY_CSWSJCMX_CJRYID foreign key (CJRYID) references RY(RYID),
|
|
|
+ constraint FK_RY_CSWSJCMX_GLRYID foreign key (GLRYID) references RY(RYID),
|
|
|
+ constraint FK_BM_CSWSJCMX_GLBMID foreign key (GLBMID) references BM(BMID)
|
|
|
+ )');
|
|
|
+
|
|
|
+ create_sequence_if_missing('CSWSJCID',
|
|
|
+ 'create sequence CSWSJCID start with 1 increment by 1 cache 20');
|
|
|
+ create_sequence_if_missing('CSWSJCMXID',
|
|
|
+ 'create sequence CSWSJCMXID start with 1 increment by 1 cache 20');
|
|
|
+
|
|
|
+ add_column_if_missing('WJJL', 'WJSJ',
|
|
|
+ 'alter table WJJL add (WJSJ timestamp(6))');
|
|
|
+ add_column_if_missing('WJJL', 'MS',
|
|
|
+ 'alter table WJJL add (MS varchar2(2048 char))');
|
|
|
+ add_column_if_missing('WJJL', 'WJLBM',
|
|
|
+ 'alter table WJJL add (WJLBM number(9))');
|
|
|
+ add_column_if_missing('WJJL', 'WJLXM',
|
|
|
+ 'alter table WJJL add (WJLXM number(9))');
|
|
|
+ add_column_if_missing('WJJL', 'JZWID',
|
|
|
+ 'alter table WJJL add (JZWID number(16))');
|
|
|
+ add_column_if_missing('WJJL', 'KFID',
|
|
|
+ 'alter table WJJL add (KFID number(16))');
|
|
|
+
|
|
|
+ select count(*) into v_count from WJJL;
|
|
|
+ if v_count <> 0 then
|
|
|
+ raise_application_error(-20201, 'WJJL 非空,停止旧列变更');
|
|
|
+ end if;
|
|
|
+
|
|
|
+ select count(*) into v_count from user_tab_columns
|
|
|
+ where table_name = 'WJJL' and column_name = 'MC';
|
|
|
+ if v_count > 0 then
|
|
|
+ execute immediate 'alter table WJJL drop column MC cascade constraints';
|
|
|
+ end if;
|
|
|
+ select count(*) into v_count from user_tab_columns
|
|
|
+ where table_name = 'WJJL' and column_name = 'WJRQ';
|
|
|
+ if v_count > 0 then
|
|
|
+ execute immediate 'alter table WJJL drop column WJRQ';
|
|
|
+ end if;
|
|
|
+ select count(*) into v_count from user_tab_columns
|
|
|
+ where table_name = 'WJJL' and column_name = 'WJSJ' and nullable = 'Y';
|
|
|
+ if v_count > 0 then
|
|
|
+ execute immediate 'alter table WJJL modify (WJSJ not null)';
|
|
|
+ end if;
|
|
|
+
|
|
|
+ add_constraint_if_missing('WJJL', 'FK_WJLB_WJJL',
|
|
|
+ 'alter table WJJL add constraint FK_WJLB_WJJL foreign key (WJLBM) references WJLB(WJLBM)');
|
|
|
+ add_constraint_if_missing('WJJL', 'FK_WJLX_WJJL',
|
|
|
+ 'alter table WJJL add constraint FK_WJLX_WJJL foreign key (WJLXM) references WJLX(WJLXM)');
|
|
|
+ add_constraint_if_missing('WJJL', 'FK_JZW_WJJL',
|
|
|
+ 'alter table WJJL add constraint FK_JZW_WJJL foreign key (JZWID) references JZW(JZWID)');
|
|
|
+ add_constraint_if_missing('WJJL', 'FK_CD_WJJL_KF',
|
|
|
+ 'alter table WJJL add constraint FK_CD_WJJL_KF foreign key (KFID) references CD(CDID)');
|
|
|
+
|
|
|
+ execute immediate 'create or replace trigger CSWSJC_IB_SETCSWSJCID
|
|
|
+ before insert on CSWSJC for each row
|
|
|
+ begin
|
|
|
+ select ''7201'' || CSWSJCID.nextval into :new.CSWSJCID from dual;
|
|
|
+ end;';
|
|
|
+ execute immediate 'create or replace trigger CSWSJCMX_IB_SETCSWSJCMXID
|
|
|
+ before insert on CSWSJCMX for each row
|
|
|
+ begin
|
|
|
+ select ''7205'' || CSWSJCMXID.nextval into :new.CSWSJCMXID from dual;
|
|
|
+ end;';
|
|
|
+ commit;
|
|
|
+ dbms_output.put_line('BUSINESS_SCHEMA_OK');
|
|
|
+end;
|
|
|
+/
|
|
|
+
|
|
|
+merge into WJLX t
|
|
|
+using (
|
|
|
+ select 1 WJLXM, '个人' MC from dual union all
|
|
|
+ select 5, '集体' from dual
|
|
|
+) s on (t.WJLXM = s.WJLXM)
|
|
|
+when matched then update set t.MC = s.MC
|
|
|
+when not matched then insert (WJLXM, MC) values (s.WJLXM, s.MC);
|
|
|
+
|
|
|
+merge into WJLB t
|
|
|
+using (
|
|
|
+ select 1 WJLBM, '严重警告' MC, 0.1 BJKF from dual union all
|
|
|
+ select 2, '记大过', 0.3 from dual union all
|
|
|
+ select 3, '留校察看', 0.3 from dual union all
|
|
|
+ select 4, '开除学籍', 0.5 from dual union all
|
|
|
+ select 5, '勒令退学', 0.5 from dual union all
|
|
|
+ select 21, '不按时作息', 4 from dual union all
|
|
|
+ select 23, '休息时间窜宿舍', 4 from dual union all
|
|
|
+ select 24, '浪费水电', 4 from dual union all
|
|
|
+ select 25, '乱扔垃圾', 4 from dual union all
|
|
|
+ select 26, '带外卖饭盒进宿舍', 4 from dual union all
|
|
|
+ select 27, '查房时间洗漱、窜宿舍', 4 from dual union all
|
|
|
+ select 29, '其他影响宿舍卫生及他人休息', 4 from dual union all
|
|
|
+ select 31, '私调空调', 10 from dual union all
|
|
|
+ select 32, '私接电源', 10 from dual union all
|
|
|
+ select 33, '私调宿舍', 10 from dual union all
|
|
|
+ select 34, '私自留宿', 15 from dual union all
|
|
|
+ select 35, '私自进入异性宿舍', 15 from dual union all
|
|
|
+ select 36, '私自离校', 20 from dual union all
|
|
|
+ select 37, '翻墙、翻越逃生窗', 10 from dual union all
|
|
|
+ select 41, '吸烟', 10 from dual union all
|
|
|
+ select 42, '饮酒', 20 from dual union all
|
|
|
+ select 43, '吸食、贩卖、藏匿毒品', 30 from dual union all
|
|
|
+ select 45, '携带藏匿违禁品(烟、酒等)', 10 from dual union all
|
|
|
+ select 46, '宿舍内售卖', 20 from dual union all
|
|
|
+ select 51, '赌博', 10 from dual union all
|
|
|
+ select 52, '盗窃', 20 from dual union all
|
|
|
+ select 53, '打架', 30 from dual union all
|
|
|
+ select 54, '破坏公物', 10 from dual union all
|
|
|
+ select 55, '高空抛物', 20 from dual union all
|
|
|
+ select 61, '冒名顶替他人考勤', 15 from dual union all
|
|
|
+ select 65, '不服从管理、顶撞辱骂管理人员', 15 from dual union all
|
|
|
+ select 71, '不按时作息(集体)', 4 from dual union all
|
|
|
+ select 72, '不按时熄灯(集体)', 4 from dual union all
|
|
|
+ select 73, '走读生进宿舍(集体)', 4 from dual union all
|
|
|
+ select 74, '浪费水电(集体)', 4 from dual union all
|
|
|
+ select 75, '乱扔垃圾(集体)', 4 from dual union all
|
|
|
+ select 76, '宿舍有烟头烟灰(集体)', 10 from dual union all
|
|
|
+ select 79, '其他影响宿舍卫生及他人休息(集体)', 4 from dual union all
|
|
|
+ select 81, '私调空调(集体)', 10 from dual union all
|
|
|
+ select 82, '不服从管理(集体)', 15 from dual union all
|
|
|
+ select 83, '堵门孔或反锁宿舍门(集体)', 4 from dual
|
|
|
+) s on (t.WJLBM = s.WJLBM)
|
|
|
+when matched then update set t.MC = s.MC, t.BJKF = s.BJKF
|
|
|
+when not matched then insert (WJLBM, MC, BJKF) values (s.WJLBM, s.MC, s.BJKF);
|
|
|
+
|
|
|
+merge into CSWSJCXM t
|
|
|
+using (
|
|
|
+ select 1 CSWSJCXMM, '场室、楼梯地板无污渍、垃圾' MC, 10 MFZ, 0 ZXZ from dual union all
|
|
|
+ select 2, '场室、走廊、楼梯处瓷砖无污渍', 10, 0 from dual union all
|
|
|
+ select 3, '场室、走廊、楼梯无香口胶印记', 10, 0 from dual union all
|
|
|
+ select 4, '场室、走廊、楼梯墙面无脚印、球印和其他污渍', 10, 0 from dual union all
|
|
|
+ select 11, '垃圾桶、拖把架、垃圾铲干净,清洁工具、桌椅摆放整齐', 5, 0 from dual union all
|
|
|
+ select 21, '讲台整洁,黑板干净', 5, 0 from dual union all
|
|
|
+ select 31, '风扇、空调箱、电脑配置箱、窗台、门窗框、黑板框、走廊、橱窗、护栏、栏杆、楼梯扶手、线槽盒等无积尘', 10, 0 from dual union all
|
|
|
+ select 32, '消防栓、灭火器、班牌、应急灯等无积尘', 5, 0 from dual union all
|
|
|
+ select 35, '玻璃光洁', 10, 0 from dual union all
|
|
|
+ select 41, '教室、走廊、楼梯天花板和墙角无蜘蛛网', 5, 0 from dual union all
|
|
|
+ select 51, '主机、显示器、键盘、电脑桌、实训设备等干净并摆放整齐', 10, 0 from dual union all
|
|
|
+ select 61, '其他', 10, 0 from dual union all
|
|
|
+ select 81, '侮辱谩骂或故意干扰检查人员检查', 0, -20 from dual
|
|
|
+) s on (t.CSWSJCXMM = s.CSWSJCXMM)
|
|
|
+when matched then update set t.MC = s.MC, t.MFZ = s.MFZ, t.ZXZ = s.ZXZ
|
|
|
+when not matched then insert (CSWSJCXMM, MC, MFZ, ZXZ)
|
|
|
+values (s.CSWSJCXMM, s.MC, s.MFZ, s.ZXZ);
|
|
|
+
|
|
|
+commit;
|
|
|
+
|
|
|
+select count(*) WJLB_COUNT from WJLB;
|
|
|
+select count(*) WJLX_COUNT from WJLX;
|
|
|
+select count(*) CSWSJCXM_COUNT from CSWSJCXM;
|
|
|
+select count(*) WJJL_COUNT from WJJL;
|