给定下表:
tableA: | tableB:
|
col1 col2 | col3 col4
----------- | ----------
1 4 | 1 x
2 5 | 2 x
3 6 | 1 z
| 2 z
| 3 z
我想在 DB2 中编写一个存储过程,通过修改 col3 的值及其从tableA
(1-4, 2-5, 3-6) 的映射,在 tableB 中添加一些行,因此添加了这些行:
通过查看行 where col4 = x
,这些行必须添加到 tableB 中:
| 4 A1 -> (only 1 changed to its mapping value 4)
| 2 A1
| 1 B1
| 5 B1 -> (only 2 changed to its mapping value 5)
| 4 C1 -> (1 changed to its mapping value 4)
| 5 C1 -> (and 2 changed to its mapping value 5)
并通过查看行 where col4 = z
,这些行必须添加到 tableB 中:
| 4 A2 -> (only 1 changed to its mapping value 4)
| 2 A2
| 3 A2
| 1 B2
| 5 B2 -> (only 2 changed to its mapping value 5)
| 3 B2
| 1 C2
| 2 C2
| 6 C2 -> (only 3 changed to its mapping value 6)
| 4 D2 -> (1 changed to its mapping value 4)
| 5 D2 -> (and 2 changed to its mapping value 5)
| 3 D2
| 4 E2 -> (1 changed to its mapping value 4)
| 2 E2
| 6 E2 -> (and 3 changed to its mapping value 6)
| 1 F2
| 5 F2 -> (2 changed to its mapping value 5)
| 6 F2 -> (and 3 changed to its mapping value 6)
| 4 G2 -> (1 changed to its mapping value 4)
| 5 G2 -> (and 2 changed to its mapping value 5)
| 6 G2 -> (and 3 changed to its mapping value 6)
请注意,在我的示例中,我有:
- 2 对 1 映射(由 2 行表示:[1,x] 和 [2,x]),因此在 tableB 中添加了 3 多行。
- 和一个 3 对 1 的映射(由 3 行表示:[1,z]、[2,z] 和 [3,z]),因此在 tableB 中添加了 7 多行。
如果我在 tableB 中有 4 对 1 映射(由 4 行表示),则必须再添加 15 行。
如果我在 tableB 中有 5 对 1 映射(由 5 行表示),则必须再添加 31 行,依此类推...
(不要将这些映射与 tableA 的映射混淆。是不同的)