2026-11-19_bzr01星级班全功能演示_01备份.sql 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. -- bzr01 星级班全功能演示数据:写入前备份。
  2. --
  3. -- 目标:C##DC / ORCLPDB
  4. -- 范围:仅测试班 BJID=40211004,时间窗口 2026-09-01 至 2026-12-01。
  5. -- 说明:备份表保留,用于 04_清理恢复.sql 恢复演示前状态。
  6. set serveroutput on
  7. whenever sqlerror exit failure
  8. alter session set current_schema = C##DC;
  9. alter session set nls_language = 'AMERICAN';
  10. declare
  11. v_schema varchar2(128) := sys_context('USERENV', 'CURRENT_SCHEMA');
  12. v_name varchar2(128);
  13. procedure create_empty(p_name varchar2, p_sql varchar2) is
  14. v_count number;
  15. begin
  16. select count(*) into v_count
  17. from all_tables
  18. where owner = v_schema and table_name = upper(p_name);
  19. if v_count = 0 then
  20. execute immediate 'create table ' || p_name || ' as ' || p_sql;
  21. end if;
  22. end;
  23. begin
  24. if v_schema <> 'C##DC' then
  25. raise_application_error(-20001, '必须使用 C##DC 执行:' || v_schema);
  26. end if;
  27. create_empty('BAK_20261119_BZR01_DEMO_BJCY',
  28. 'select * from BJCY where 1=0');
  29. create_empty('BAK_20261119_BZR01_DEMO_RY',
  30. 'select * from RY where 1=0');
  31. create_empty('BAK_20261119_BZR01_DEMO_SSNWJC',
  32. 'select * from SSNWJC where 1=0');
  33. create_empty('BAK_20261119_BZR01_DEMO_SSNWJCMX',
  34. 'select * from SSNWJCMX where 1=0');
  35. create_empty('BAK_20261119_BZR01_DEMO_SSNWJCXY',
  36. 'select * from SSNWJCXY where 1=0');
  37. create_empty('BAK_20261119_BZR01_DEMO_SQLJC',
  38. 'select * from SQLJC where 1=0');
  39. create_empty('BAK_20261119_BZR01_DEMO_SQLJCMX',
  40. 'select * from SQLJCMX where 1=0');
  41. create_empty('BAK_20261119_BZR01_DEMO_CSWSJC',
  42. 'select * from CSWSJC where 1=0');
  43. create_empty('BAK_20261119_BZR01_DEMO_CSWSJCMX',
  44. 'select * from CSWSJCMX where 1=0');
  45. create_empty('BAK_20261119_BZR01_DEMO_KCB',
  46. 'select * from KCB where 1=0');
  47. create_empty('BAK_20261119_BZR01_DEMO_KTJL',
  48. 'select * from KTJL where 1=0');
  49. create_empty('BAK_20261119_BZR01_DEMO_KTJLMX',
  50. 'select * from KTJLMX where 1=0');
  51. create_empty('BAK_20261119_BZR01_DEMO_KQJL',
  52. 'select * from KQJL where 1=0');
  53. create_empty('BAK_20261119_BZR01_DEMO_WJJL',
  54. 'select * from WJJL where 1=0');
  55. create_empty('BAK_20261119_BZR01_DEMO_WJJLCY',
  56. 'select * from WJJLCY where 1=0');
  57. create_empty('BAK_20261119_BZR01_DEMO_HJJL',
  58. 'select * from HJJL where 1=0');
  59. create_empty('BAK_20261119_BZR01_DEMO_HJJLCY',
  60. 'select * from HJJLCY where 1=0');
  61. create_empty('BAK_20261119_BZR01_DEMO_XJB_JD',
  62. 'select * from XJB_JD where 1=0');
  63. create_empty('BAK_20261119_BZR01_DEMO_XJB_JG',
  64. 'select * from XJB_JG where 1=0');
  65. create_empty('BAK_20261119_BZR01_DEMO_XJB_PM',
  66. 'select * from XJB_PM where 1=0');
  67. create_empty('BAK_20261119_BZR01_DEMO_XJB_JFJL',
  68. 'select * from XJB_JFJL where 1=0');
  69. dbms_output.put_line('backup_tables_ready=21');
  70. end;
  71. /
  72. begin
  73. -- 演示学生会修改姓名以贴近真实校园场景,先保存原始人员主数据。
  74. insert into BAK_20261119_BZR01_DEMO_RY
  75. select r.* from RY r
  76. where r.RYID in (111157259,111157260,111157261,111157262)
  77. and not exists (
  78. select 1 from BAK_20261119_BZR01_DEMO_RY x
  79. where x.RYID = r.RYID);
  80. -- 班级成员状态。
  81. insert into BAK_20261119_BZR01_DEMO_BJCY
  82. select b.* from BJCY b
  83. where b.BJID = 40211004
  84. and not exists (
  85. select 1 from BAK_20261119_BZR01_DEMO_BJCY x
  86. where x.BJCYID = b.BJCYID);
  87. -- 宿舍检查及明细。
  88. insert into BAK_20261119_BZR01_DEMO_SSNWJC
  89. select s.* from SSNWJC s
  90. where s.BJID = 40211004
  91. and s.JCSJ >= timestamp '2026-09-01 00:00:00'
  92. and s.JCSJ < timestamp '2026-12-01 00:00:00'
  93. and not exists (
  94. select 1 from BAK_20261119_BZR01_DEMO_SSNWJC x
  95. where x.SSNWJCID = s.SSNWJCID);
  96. insert into BAK_20261119_BZR01_DEMO_SSNWJCMX
  97. select m.* from SSNWJCMX m
  98. where m.SSNWJCID in (
  99. select s.SSNWJCID from SSNWJC s
  100. where s.BJID = 40211004
  101. and s.JCSJ >= timestamp '2026-09-01 00:00:00'
  102. and s.JCSJ < timestamp '2026-12-01 00:00:00')
  103. and not exists (
  104. select 1 from BAK_20261119_BZR01_DEMO_SSNWJCMX x
  105. where x.SSNWJCMXID = m.SSNWJCMXID);
  106. insert into BAK_20261119_BZR01_DEMO_SSNWJCXY
  107. select x.* from SSNWJCXY x
  108. where x.SSNWJCID in (
  109. select s.SSNWJCID from SSNWJC s
  110. where s.BJID = 40211004
  111. and s.JCSJ >= timestamp '2026-09-01 00:00:00'
  112. and s.JCSJ < timestamp '2026-12-01 00:00:00')
  113. and not exists (
  114. select 1 from BAK_20261119_BZR01_DEMO_SSNWJCXY b
  115. where b.SSNWJCXYID = x.SSNWJCXYID);
  116. -- 升旗礼及明细。
  117. insert into BAK_20261119_BZR01_DEMO_SQLJC
  118. select s.* from SQLJC s
  119. where s.BJID = 40211004
  120. and s.JCSJ >= timestamp '2026-09-01 00:00:00'
  121. and s.JCSJ < timestamp '2026-12-01 00:00:00'
  122. and not exists (
  123. select 1 from BAK_20261119_BZR01_DEMO_SQLJC x
  124. where x.SQLJCID = s.SQLJCID);
  125. insert into BAK_20261119_BZR01_DEMO_SQLJCMX
  126. select m.* from SQLJCMX m
  127. where m.SQLJCID in (
  128. select s.SQLJCID from SQLJC s
  129. where s.BJID = 40211004
  130. and s.JCSJ >= timestamp '2026-09-01 00:00:00'
  131. and s.JCSJ < timestamp '2026-12-01 00:00:00')
  132. and not exists (
  133. select 1 from BAK_20261119_BZR01_DEMO_SQLJCMX x
  134. where x.SQLJCMXID = m.SQLJCMXID);
  135. -- 场室卫生及明细。
  136. insert into BAK_20261119_BZR01_DEMO_CSWSJC
  137. select s.* from CSWSJC s
  138. where s.BJID = 40211004
  139. and s.JCSJ >= timestamp '2026-09-01 00:00:00'
  140. and s.JCSJ < timestamp '2026-12-01 00:00:00'
  141. and not exists (
  142. select 1 from BAK_20261119_BZR01_DEMO_CSWSJC x
  143. where x.CSWSJCID = s.CSWSJCID);
  144. insert into BAK_20261119_BZR01_DEMO_CSWSJCMX
  145. select m.* from CSWSJCMX m
  146. where m.CSWSJCID in (
  147. select s.CSWSJCID from CSWSJC s
  148. where s.BJID = 40211004
  149. and s.JCSJ >= timestamp '2026-09-01 00:00:00'
  150. and s.JCSJ < timestamp '2026-12-01 00:00:00')
  151. and not exists (
  152. select 1 from BAK_20261119_BZR01_DEMO_CSWSJCMX x
  153. where x.CSWSJCMXID = m.CSWSJCMXID);
  154. -- 课程、课堂日志及评分。
  155. insert into BAK_20261119_BZR01_DEMO_KCB
  156. select k.* from KCB k
  157. where k.BJID = 40211004
  158. and k.KSSJ >= timestamp '2026-09-01 00:00:00'
  159. and k.KSSJ < timestamp '2026-12-01 00:00:00'
  160. and not exists (
  161. select 1 from BAK_20261119_BZR01_DEMO_KCB x
  162. where x.KCBID = k.KCBID);
  163. insert into BAK_20261119_BZR01_DEMO_KTJL
  164. select j.* from KTJL j
  165. where j.BJID = 40211004
  166. and j.JLSJ >= timestamp '2026-09-01 00:00:00'
  167. and j.JLSJ < timestamp '2026-12-01 00:00:00'
  168. and not exists (
  169. select 1 from BAK_20261119_BZR01_DEMO_KTJL x
  170. where x.KTJLID = j.KTJLID);
  171. insert into BAK_20261119_BZR01_DEMO_KTJLMX
  172. select m.* from KTJLMX m
  173. where m.KTJLID in (
  174. select j.KTJLID from KTJL j
  175. where j.BJID = 40211004
  176. and j.JLSJ >= timestamp '2026-09-01 00:00:00'
  177. and j.JLSJ < timestamp '2026-12-01 00:00:00')
  178. and not exists (
  179. select 1 from BAK_20261119_BZR01_DEMO_KTJLMX x
  180. where x.KTJLMXID = m.KTJLMXID);
  181. -- 考勤。
  182. insert into BAK_20261119_BZR01_DEMO_KQJL
  183. select k.* from KQJL k
  184. where k.BJID = 40211004
  185. and k.KSSJ >= timestamp '2026-09-01 00:00:00'
  186. and k.KSSJ < timestamp '2026-12-01 00:00:00'
  187. and not exists (
  188. select 1 from BAK_20261119_BZR01_DEMO_KQJL x
  189. where x.KQJLID = k.KQJLID);
  190. -- 个人/集体违纪。
  191. insert into BAK_20261119_BZR01_DEMO_WJJL
  192. select w.* from WJJL w
  193. where w.BJID = 40211004
  194. and w.WJSJ >= timestamp '2026-09-01 00:00:00'
  195. and w.WJSJ < timestamp '2026-12-01 00:00:00'
  196. and not exists (
  197. select 1 from BAK_20261119_BZR01_DEMO_WJJL x
  198. where x.WJJLID = w.WJJLID);
  199. insert into BAK_20261119_BZR01_DEMO_WJJLCY
  200. select c.* from WJJLCY c
  201. where c.WJJLID in (
  202. select w.WJJLID from WJJL w
  203. where w.BJID = 40211004
  204. and w.WJSJ >= timestamp '2026-09-01 00:00:00'
  205. and w.WJSJ < timestamp '2026-12-01 00:00:00')
  206. and not exists (
  207. select 1 from BAK_20261119_BZR01_DEMO_WJJLCY x
  208. where x.WJJLCYID = c.WJJLCYID);
  209. -- 个人/集体获奖。
  210. insert into BAK_20261119_BZR01_DEMO_HJJL
  211. select h.* from HJJL h
  212. where h.BJID = 40211004
  213. and h.HJRQ >= date '2026-09-01'
  214. and h.HJRQ < date '2026-12-01'
  215. and not exists (
  216. select 1 from BAK_20261119_BZR01_DEMO_HJJL x
  217. where x.HJJLID = h.HJJLID);
  218. insert into BAK_20261119_BZR01_DEMO_HJJLCY
  219. select c.* from HJJLCY c
  220. where c.HJJLID in (
  221. select h.HJJLID from HJJL h
  222. where h.BJID = 40211004
  223. and h.HJRQ >= date '2026-09-01'
  224. and h.HJRQ < date '2026-12-01')
  225. and not exists (
  226. select 1 from BAK_20261119_BZR01_DEMO_HJJLCY x
  227. where x.HJJLCYID = c.HJJLCYID);
  228. -- 月结批次、结果、排名和增扣分账本。
  229. insert into BAK_20261119_BZR01_DEMO_XJB_JD
  230. select j.* from XJB_JD j
  231. where j.XJB_JDID in (
  232. select g.XJB_JDID from XJB_JG g
  233. where g.BJID = 40211004
  234. and g.NDY in ('2026-09','2026-10','2026-11'))
  235. and not exists (
  236. select 1 from BAK_20261119_BZR01_DEMO_XJB_JD x
  237. where x.XJB_JDID = j.XJB_JDID);
  238. insert into BAK_20261119_BZR01_DEMO_XJB_JG
  239. select g.* from XJB_JG g
  240. where g.BJID = 40211004
  241. and g.NDY in ('2026-09','2026-10','2026-11')
  242. and not exists (
  243. select 1 from BAK_20261119_BZR01_DEMO_XJB_JG x
  244. where x.XJB_JGID = g.XJB_JGID);
  245. insert into BAK_20261119_BZR01_DEMO_XJB_PM
  246. select p.* from XJB_PM p
  247. where p.BJID = 40211004
  248. and p.XJB_JDID in (
  249. select g.XJB_JDID from XJB_JG g
  250. where g.BJID = 40211004
  251. and g.NDY in ('2026-09','2026-10','2026-11'))
  252. and not exists (
  253. select 1 from BAK_20261119_BZR01_DEMO_XJB_PM x
  254. where x.XJB_PMID = p.XJB_PMID);
  255. insert into BAK_20261119_BZR01_DEMO_XJB_JFJL
  256. select j.* from XJB_JFJL j
  257. where j.BJID = 40211004
  258. and j.NDY in ('2026-09','2026-10','2026-11')
  259. and not exists (
  260. select 1 from BAK_20261119_BZR01_DEMO_XJB_JFJL x
  261. where x.XJB_JFJLID = j.XJB_JFJLID);
  262. commit;
  263. dbms_output.put_line('backup_rows_copied=ok');
  264. end;
  265. /
  266. select 'BJCY' TABLE_NAME,count(*) ROW_COUNT from BAK_20261119_BZR01_DEMO_BJCY
  267. union all select 'SSNWJC',count(*) from BAK_20261119_BZR01_DEMO_SSNWJC
  268. union all select 'SSNWJCMX',count(*) from BAK_20261119_BZR01_DEMO_SSNWJCMX
  269. union all select 'SSNWJCXY',count(*) from BAK_20261119_BZR01_DEMO_SSNWJCXY
  270. union all select 'SQLJC',count(*) from BAK_20261119_BZR01_DEMO_SQLJC
  271. union all select 'SQLJCMX',count(*) from BAK_20261119_BZR01_DEMO_SQLJCMX
  272. union all select 'CSWSJC',count(*) from BAK_20261119_BZR01_DEMO_CSWSJC
  273. union all select 'CSWSJCMX',count(*) from BAK_20261119_BZR01_DEMO_CSWSJCMX
  274. union all select 'KCB',count(*) from BAK_20261119_BZR01_DEMO_KCB
  275. union all select 'KTJL',count(*) from BAK_20261119_BZR01_DEMO_KTJL
  276. union all select 'KTJLMX',count(*) from BAK_20261119_BZR01_DEMO_KTJLMX
  277. union all select 'KQJL',count(*) from BAK_20261119_BZR01_DEMO_KQJL
  278. union all select 'WJJL',count(*) from BAK_20261119_BZR01_DEMO_WJJL
  279. union all select 'WJJLCY',count(*) from BAK_20261119_BZR01_DEMO_WJJLCY
  280. union all select 'HJJL',count(*) from BAK_20261119_BZR01_DEMO_HJJL
  281. union all select 'HJJLCY',count(*) from BAK_20261119_BZR01_DEMO_HJJLCY
  282. union all select 'XJB_JD',count(*) from BAK_20261119_BZR01_DEMO_XJB_JD
  283. union all select 'XJB_JG',count(*) from BAK_20261119_BZR01_DEMO_XJB_JG
  284. union all select 'XJB_PM',count(*) from BAK_20261119_BZR01_DEMO_XJB_PM
  285. union all select 'XJB_JFJL',count(*) from BAK_20261119_BZR01_DEMO_XJB_JFJL;
  286. exit