个体关系koucx.sql 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --初始化个体关系
  2. CREATE OR REPLACE PROCEDURE shanglifeecif.initIndRelationShip() IS
  3. DECLARE
  4. BEGIN
  5. DELETE FROM shanglifeecif.IndRelationShip;
  6. --从保单信息表(POLICY_INFORMATION)获取投保人和被保人的关系并
  7. insert into shanglifeecif.IndRelationShip(irsid,RSType,IndID1,Name1,IDCard1,IndID2,Name2,IDCard2,RSSTime,Role2)
  8. SELECT row_number()over(),max(RELATIONTOAPPNT),CUSTOMERNO,max(NAME),max(IDNO),INSUREDNO,max(INSUREDNAME),max(INSUREDIDNO),min(CUSTOMGETPOLDATE),
  9. CASE max(RELATIONTOAPPNT)
  10. WHEN '子女' THEN case max(INSUREDSEX) when 1 THEN '女儿' WHEN 0 THEN '儿子' end
  11. when '父母' THEN case max(INSUREDSEX) when 1 THEN '母亲' WHEN 0 THEN '父亲' end
  12. WHEN '配偶' THEN case max(INSUREDSEX) when 1 THEN '妻子' WHEN 0 THEN '丈夫' end
  13. when '祖父母、外祖父母' THEN case max(INSUREDSEX) when 1 THEN '(外)祖母' WHEN 0 THEN '(外)祖父' end
  14. when '祖孙、外祖孙' THEN case max(INSUREDSEX) when 1 THEN '(外)孙女' WHEN 0 THEN '(外)祖孙' end
  15. ELSE max(RELATIONTOAPPNT) END
  16. FROM shanghailifeecif.POLICY_INFORMATION
  17. WHERE RELATIONTOAPPNT<>'本人'
  18. GROUP BY CUSTOMERNO,INSUREDNO;
  19. --更新IndRelationShip.Role1为IndRelationShip.Role2的相对角色,即role2为母亲则role1为父亲等
  20. UPDATE shanglifeecif.IndRelationShip sirs SET sirs.role1 = (SELECT
  21. CASE slirs.role2
  22. WHEN '父亲' THEN '母亲'
  23. WHEN '母亲' THEN '父亲'
  24. WHEN '丈夫' THEN '妻子'
  25. WHEN '妻子' THEN '丈夫'
  26. WHEN '儿子' THEN '女儿'
  27. WHEN '女儿' THEN '儿子'
  28. ELSE '其它' END
  29. FROM shanglifeecif.IndRelationShip slirs WHERE sirs.irsid = slirs.irsid);
  30. --此时插入IndRelationShip的IndID1,IndID2为上游系统客户号,根据Individual.SCustID更新为Individual.IndID
  31. UPDATE shanglifeecif.IndRelationShip sirs SET (sirs.indid1) =
  32. (SELECT si.indid FROM shanglifeecif.individual si WHERE si.scustid = sirs.indid1);
  33. UPDATE shanglifeecif.IndRelationShip sirs SET (sirs.indid2) =
  34. (SELECT si.indid FROM shanglifeecif.individual si WHERE si.scustid = sirs.indid2);
  35. EXCEPTION
  36. WHEN HIVE_EXCEPTION THEN
  37. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  38. WHEN Others THEN
  39. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  40. END ;