| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- -- bzr01 星级班全功能演示数据:写入前备份。
- --
- -- 目标:C##DC / ORCLPDB
- -- 范围:仅测试班 BJID=40211004,时间窗口 2026-09-01 至 2026-12-01。
- -- 说明:备份表保留,用于 04_清理恢复.sql 恢复演示前状态。
- set serveroutput on
- whenever sqlerror exit failure
- alter session set current_schema = C##DC;
- alter session set nls_language = 'AMERICAN';
- declare
- v_schema varchar2(128) := sys_context('USERENV', 'CURRENT_SCHEMA');
- v_name varchar2(128);
- procedure create_empty(p_name varchar2, p_sql varchar2) is
- v_count number;
- begin
- select count(*) into v_count
- from all_tables
- where owner = v_schema and table_name = upper(p_name);
- if v_count = 0 then
- execute immediate 'create table ' || p_name || ' as ' || p_sql;
- end if;
- end;
- begin
- if v_schema <> 'C##DC' then
- raise_application_error(-20001, '必须使用 C##DC 执行:' || v_schema);
- end if;
- create_empty('BAK_20261119_BZR01_DEMO_BJCY',
- 'select * from BJCY where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_RY',
- 'select * from RY where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_SSNWJC',
- 'select * from SSNWJC where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_SSNWJCMX',
- 'select * from SSNWJCMX where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_SSNWJCXY',
- 'select * from SSNWJCXY where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_SQLJC',
- 'select * from SQLJC where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_SQLJCMX',
- 'select * from SQLJCMX where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_CSWSJC',
- 'select * from CSWSJC where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_CSWSJCMX',
- 'select * from CSWSJCMX where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_KCB',
- 'select * from KCB where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_KTJL',
- 'select * from KTJL where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_KTJLMX',
- 'select * from KTJLMX where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_KQJL',
- 'select * from KQJL where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_WJJL',
- 'select * from WJJL where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_WJJLCY',
- 'select * from WJJLCY where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_HJJL',
- 'select * from HJJL where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_HJJLCY',
- 'select * from HJJLCY where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_XJB_JD',
- 'select * from XJB_JD where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_XJB_JG',
- 'select * from XJB_JG where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_XJB_PM',
- 'select * from XJB_PM where 1=0');
- create_empty('BAK_20261119_BZR01_DEMO_XJB_JFJL',
- 'select * from XJB_JFJL where 1=0');
- dbms_output.put_line('backup_tables_ready=21');
- end;
- /
- begin
- -- 演示学生会修改姓名以贴近真实校园场景,先保存原始人员主数据。
- insert into BAK_20261119_BZR01_DEMO_RY
- select r.* from RY r
- where r.RYID in (111157259,111157260,111157261,111157262)
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_RY x
- where x.RYID = r.RYID);
- -- 班级成员状态。
- insert into BAK_20261119_BZR01_DEMO_BJCY
- select b.* from BJCY b
- where b.BJID = 40211004
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_BJCY x
- where x.BJCYID = b.BJCYID);
- -- 宿舍检查及明细。
- insert into BAK_20261119_BZR01_DEMO_SSNWJC
- select s.* from SSNWJC s
- where s.BJID = 40211004
- and s.JCSJ >= timestamp '2026-09-01 00:00:00'
- and s.JCSJ < timestamp '2026-12-01 00:00:00'
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_SSNWJC x
- where x.SSNWJCID = s.SSNWJCID);
- insert into BAK_20261119_BZR01_DEMO_SSNWJCMX
- select m.* from SSNWJCMX m
- where m.SSNWJCID in (
- select s.SSNWJCID from SSNWJC s
- where s.BJID = 40211004
- and s.JCSJ >= timestamp '2026-09-01 00:00:00'
- and s.JCSJ < timestamp '2026-12-01 00:00:00')
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_SSNWJCMX x
- where x.SSNWJCMXID = m.SSNWJCMXID);
- insert into BAK_20261119_BZR01_DEMO_SSNWJCXY
- select x.* from SSNWJCXY x
- where x.SSNWJCID in (
- select s.SSNWJCID from SSNWJC s
- where s.BJID = 40211004
- and s.JCSJ >= timestamp '2026-09-01 00:00:00'
- and s.JCSJ < timestamp '2026-12-01 00:00:00')
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_SSNWJCXY b
- where b.SSNWJCXYID = x.SSNWJCXYID);
- -- 升旗礼及明细。
- insert into BAK_20261119_BZR01_DEMO_SQLJC
- select s.* from SQLJC s
- where s.BJID = 40211004
- and s.JCSJ >= timestamp '2026-09-01 00:00:00'
- and s.JCSJ < timestamp '2026-12-01 00:00:00'
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_SQLJC x
- where x.SQLJCID = s.SQLJCID);
- insert into BAK_20261119_BZR01_DEMO_SQLJCMX
- select m.* from SQLJCMX m
- where m.SQLJCID in (
- select s.SQLJCID from SQLJC s
- where s.BJID = 40211004
- and s.JCSJ >= timestamp '2026-09-01 00:00:00'
- and s.JCSJ < timestamp '2026-12-01 00:00:00')
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_SQLJCMX x
- where x.SQLJCMXID = m.SQLJCMXID);
- -- 场室卫生及明细。
- insert into BAK_20261119_BZR01_DEMO_CSWSJC
- select s.* from CSWSJC s
- where s.BJID = 40211004
- and s.JCSJ >= timestamp '2026-09-01 00:00:00'
- and s.JCSJ < timestamp '2026-12-01 00:00:00'
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_CSWSJC x
- where x.CSWSJCID = s.CSWSJCID);
- insert into BAK_20261119_BZR01_DEMO_CSWSJCMX
- select m.* from CSWSJCMX m
- where m.CSWSJCID in (
- select s.CSWSJCID from CSWSJC s
- where s.BJID = 40211004
- and s.JCSJ >= timestamp '2026-09-01 00:00:00'
- and s.JCSJ < timestamp '2026-12-01 00:00:00')
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_CSWSJCMX x
- where x.CSWSJCMXID = m.CSWSJCMXID);
- -- 课程、课堂日志及评分。
- insert into BAK_20261119_BZR01_DEMO_KCB
- select k.* from KCB k
- where k.BJID = 40211004
- and k.KSSJ >= timestamp '2026-09-01 00:00:00'
- and k.KSSJ < timestamp '2026-12-01 00:00:00'
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_KCB x
- where x.KCBID = k.KCBID);
- insert into BAK_20261119_BZR01_DEMO_KTJL
- select j.* from KTJL j
- where j.BJID = 40211004
- and j.JLSJ >= timestamp '2026-09-01 00:00:00'
- and j.JLSJ < timestamp '2026-12-01 00:00:00'
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_KTJL x
- where x.KTJLID = j.KTJLID);
- insert into BAK_20261119_BZR01_DEMO_KTJLMX
- select m.* from KTJLMX m
- where m.KTJLID in (
- select j.KTJLID from KTJL j
- where j.BJID = 40211004
- and j.JLSJ >= timestamp '2026-09-01 00:00:00'
- and j.JLSJ < timestamp '2026-12-01 00:00:00')
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_KTJLMX x
- where x.KTJLMXID = m.KTJLMXID);
- -- 考勤。
- insert into BAK_20261119_BZR01_DEMO_KQJL
- select k.* from KQJL k
- where k.BJID = 40211004
- and k.KSSJ >= timestamp '2026-09-01 00:00:00'
- and k.KSSJ < timestamp '2026-12-01 00:00:00'
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_KQJL x
- where x.KQJLID = k.KQJLID);
- -- 个人/集体违纪。
- insert into BAK_20261119_BZR01_DEMO_WJJL
- select w.* from WJJL w
- where w.BJID = 40211004
- and w.WJSJ >= timestamp '2026-09-01 00:00:00'
- and w.WJSJ < timestamp '2026-12-01 00:00:00'
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_WJJL x
- where x.WJJLID = w.WJJLID);
- insert into BAK_20261119_BZR01_DEMO_WJJLCY
- select c.* from WJJLCY c
- where c.WJJLID in (
- select w.WJJLID from WJJL w
- where w.BJID = 40211004
- and w.WJSJ >= timestamp '2026-09-01 00:00:00'
- and w.WJSJ < timestamp '2026-12-01 00:00:00')
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_WJJLCY x
- where x.WJJLCYID = c.WJJLCYID);
- -- 个人/集体获奖。
- insert into BAK_20261119_BZR01_DEMO_HJJL
- select h.* from HJJL h
- where h.BJID = 40211004
- and h.HJRQ >= date '2026-09-01'
- and h.HJRQ < date '2026-12-01'
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_HJJL x
- where x.HJJLID = h.HJJLID);
- insert into BAK_20261119_BZR01_DEMO_HJJLCY
- select c.* from HJJLCY c
- where c.HJJLID in (
- select h.HJJLID from HJJL h
- where h.BJID = 40211004
- and h.HJRQ >= date '2026-09-01'
- and h.HJRQ < date '2026-12-01')
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_HJJLCY x
- where x.HJJLCYID = c.HJJLCYID);
- -- 月结批次、结果、排名和增扣分账本。
- insert into BAK_20261119_BZR01_DEMO_XJB_JD
- select j.* from XJB_JD j
- where j.XJB_JDID in (
- select g.XJB_JDID from XJB_JG g
- where g.BJID = 40211004
- and g.NDY in ('2026-09','2026-10','2026-11'))
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_XJB_JD x
- where x.XJB_JDID = j.XJB_JDID);
- insert into BAK_20261119_BZR01_DEMO_XJB_JG
- select g.* from XJB_JG g
- where g.BJID = 40211004
- and g.NDY in ('2026-09','2026-10','2026-11')
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_XJB_JG x
- where x.XJB_JGID = g.XJB_JGID);
- insert into BAK_20261119_BZR01_DEMO_XJB_PM
- select p.* from XJB_PM p
- where p.BJID = 40211004
- and p.XJB_JDID in (
- select g.XJB_JDID from XJB_JG g
- where g.BJID = 40211004
- and g.NDY in ('2026-09','2026-10','2026-11'))
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_XJB_PM x
- where x.XJB_PMID = p.XJB_PMID);
- insert into BAK_20261119_BZR01_DEMO_XJB_JFJL
- select j.* from XJB_JFJL j
- where j.BJID = 40211004
- and j.NDY in ('2026-09','2026-10','2026-11')
- and not exists (
- select 1 from BAK_20261119_BZR01_DEMO_XJB_JFJL x
- where x.XJB_JFJLID = j.XJB_JFJLID);
- commit;
- dbms_output.put_line('backup_rows_copied=ok');
- end;
- /
- select 'BJCY' TABLE_NAME,count(*) ROW_COUNT from BAK_20261119_BZR01_DEMO_BJCY
- union all select 'SSNWJC',count(*) from BAK_20261119_BZR01_DEMO_SSNWJC
- union all select 'SSNWJCMX',count(*) from BAK_20261119_BZR01_DEMO_SSNWJCMX
- union all select 'SSNWJCXY',count(*) from BAK_20261119_BZR01_DEMO_SSNWJCXY
- union all select 'SQLJC',count(*) from BAK_20261119_BZR01_DEMO_SQLJC
- union all select 'SQLJCMX',count(*) from BAK_20261119_BZR01_DEMO_SQLJCMX
- union all select 'CSWSJC',count(*) from BAK_20261119_BZR01_DEMO_CSWSJC
- union all select 'CSWSJCMX',count(*) from BAK_20261119_BZR01_DEMO_CSWSJCMX
- union all select 'KCB',count(*) from BAK_20261119_BZR01_DEMO_KCB
- union all select 'KTJL',count(*) from BAK_20261119_BZR01_DEMO_KTJL
- union all select 'KTJLMX',count(*) from BAK_20261119_BZR01_DEMO_KTJLMX
- union all select 'KQJL',count(*) from BAK_20261119_BZR01_DEMO_KQJL
- union all select 'WJJL',count(*) from BAK_20261119_BZR01_DEMO_WJJL
- union all select 'WJJLCY',count(*) from BAK_20261119_BZR01_DEMO_WJJLCY
- union all select 'HJJL',count(*) from BAK_20261119_BZR01_DEMO_HJJL
- union all select 'HJJLCY',count(*) from BAK_20261119_BZR01_DEMO_HJJLCY
- union all select 'XJB_JD',count(*) from BAK_20261119_BZR01_DEMO_XJB_JD
- union all select 'XJB_JG',count(*) from BAK_20261119_BZR01_DEMO_XJB_JG
- union all select 'XJB_PM',count(*) from BAK_20261119_BZR01_DEMO_XJB_PM
- union all select 'XJB_JFJL',count(*) from BAK_20261119_BZR01_DEMO_XJB_JFJL;
- exit
|