个体关系存储过程.sql 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.init_indrelationship_main( )
  2. IS
  3. BEGIN
  4. DELETE FROM shanglifeecif.IndRelationShip;
  5. --从保单信息表(POLICY_INFORMATION)获取投保人和被保人的关系并
  6. insert into shanglifeecif.IndRelationShip(
  7. irsid,
  8. RSType,
  9. IndID1,
  10. Name1,
  11. IDCard1,
  12. Role1,
  13. IndID2,
  14. Name2,
  15. IDCard2,
  16. RSSTime,
  17. Role2
  18. )
  19. SELECT
  20. row_number()over(),
  21. max(p.RELATIONTOAPPNT),
  22. p.CUSTOMERNO,
  23. max(p.NAME),
  24. max(p.IDNO),
  25. CASE max(p.RELATIONTOAPPNT)
  26. WHEN '子女'
  27. THEN CASE max(p.sex)
  28. WHEN 1 THEN '母亲'
  29. WHEN 0 THEN '父亲'
  30. END
  31. WHEN '父母'
  32. THEN CASE max(p.sex)
  33. WHEN 1 THEN '女儿'
  34. WHEN 0 THEN '儿子'
  35. END
  36. WHEN '配偶'
  37. THEN CASE max(p.sex)
  38. WHEN 1 THEN '妻子'
  39. WHEN 0 THEN '丈夫'
  40. END
  41. WHEN '祖父母、外祖父母'
  42. THEN CASE max(p.sex)
  43. WHEN 1 THEN '(外)孙女'
  44. WHEN 0 THEN '(外)祖孙'
  45. END
  46. WHEN '祖孙、外祖孙'
  47. THEN CASE max(p.sex)
  48. WHEN 1 THEN '(外)祖母'
  49. WHEN 0 THEN '(外)祖父'
  50. END
  51. ELSE max(p.RELATIONTOAPPNT)
  52. END AS Role1,
  53. p.INSUREDNO,
  54. max(p.INSUREDNAME),
  55. max(p.INSUREDIDNO),
  56. min(p.CUSTOMGETPOLDATE),
  57. CASE max(p.RELATIONTOAPPNT)
  58. WHEN '子女'
  59. THEN CASE max(p.INSUREDSEX)
  60. WHEN 1 THEN '女儿'
  61. WHEN 0 THEN '儿子'
  62. END
  63. WHEN '父母'
  64. THEN CASE max(p.INSUREDSEX)
  65. WHEN 1 THEN '母亲'
  66. WHEN 0 THEN '父亲'
  67. END
  68. WHEN '配偶'
  69. THEN CASE max(p.INSUREDSEX)
  70. WHEN 1 THEN '妻子'
  71. WHEN 0 THEN '丈夫'
  72. END
  73. WHEN '祖父母、外祖父母'
  74. THEN CASE max(p.INSUREDSEX)
  75. WHEN 1 THEN '(外)祖母'
  76. WHEN 0 THEN '(外)祖父'
  77. END
  78. WHEN '祖孙、外祖孙'
  79. THEN CASE max(p.INSUREDSEX)
  80. WHEN 1 THEN '(外)孙女'
  81. WHEN 0 THEN '(外)祖孙'
  82. END
  83. ELSE max(p.RELATIONTOAPPNT)
  84. END AS Role2
  85. FROM shanghailifeecif.POLICY_INFORMATION p
  86. WHERE p.RELATIONTOAPPNT<>'本人'
  87. GROUP BY p.CUSTOMERNO,p.INSUREDNO;
  88. --此时插入IndRelationShip的IndID1,IndID2为上游系统客户号,根据Individual.SCustID更新为Individual.IndID
  89. UPDATE shanglifeecif.IndRelationShip sirs SET sirs.indid1 =
  90. (SELECT si.indid FROM shanglifeecif.individual si WHERE si.scustid = sirs.indid1);
  91. UPDATE shanglifeecif.IndRelationShip sirs SET sirs.indid2 =
  92. (SELECT si.indid FROM shanglifeecif.individual si WHERE si.scustid = sirs.indid2);
  93. END;