up_other_customerinfo.sql 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.up_other_customerinfo() -- 创建存储过程
  2. IS
  3. BEGIN
  4. --更新客户类型投保人
  5. UPDATE shanglifeecif.individual i SET i.custtype = '投保人' WHERE
  6. i.scustid IN (SELECT p.customerno FROM dsj.policy_information p);
  7. --更新客户类型投保人、被保人
  8. UPDATE shanglifeecif.individual i SET i.custtype = '被保人' WHERE
  9. i.scustid IN (SELECT pi.insuredno FROM dsj.policy_information pi);
  10. --更新客户类型投保人、被保人
  11. UPDATE shanglifeecif.individual i SET i.custtype = '投保人、被保人' WHERE
  12. i.scustid IN (SELECT p.customerno FROM dsj.policy_information p)
  13. AND i.scustid IN (SELECT pi.insuredno FROM dsj.policy_information pi);
  14. --更新业绩归属
  15. UPDATE shanglifeecif.Individual si1 SET si1.policybelong = (
  16. SELECT trim(t.SALECOM) FROM (
  17. SELECT row_number()OVER(PARTITION BY p.customerno ORDER BY p.polapplydate asc) rd,p.customerno,p.SALECOM FROM dsj.policy_information p
  18. ) t WHERE t.rd = 1 AND si1.scustid = t.customerno
  19. );
  20. UPDATE shanglifeecif.Individual si1 SET si1.policybelong = (
  21. SELECT trim(t.SALECOM) FROM (
  22. SELECT row_number()OVER(PARTITION BY p.insuredno ORDER BY p.polapplydate asc) rd,p.insuredno,p.SALECOM FROM dsj.policy_information p
  23. ) t WHERE t.rd = 1 AND si1.scustid = t.insuredno
  24. );
  25. --更新职业,民族等信息
  26. UPDATE shanglifeecif.Individual si1 SET (si1.Occupation,si1.Ethnic,si1.education) = (
  27. SELECT trim(t.occupationname),trim(t.NATIONALITYNAME),trim(t.degree) FROM (
  28. SELECT row_number()OVER(PARTITION BY p.customerno ORDER BY p.polapplydate desc) rd,p.customerno,p.occupationname,p.NATIONALITYNAME,p.degree FROM dsj.policy_information p
  29. ) t WHERE t.rd = 1 AND si1.scustid = t.customerno
  30. );
  31. --更新官微积分
  32. UPDATE shanglifeecif.individual si SET si.officialCalculus = (
  33. SELECT temp.available_points FROM (SELECT t.available_points,t.certificate_no,row_number()OVER(PARTITION BY t.certificate_no ORDER BY t.gmt_created DESC) rd FROM dsj.t_account t) temp WHERE temp.rd = 1 AND temp.certificate_no = si.idcard
  34. );
  35. dbms_output.put_line('up_other_customerinfo函数跑批完成!');
  36. EXCEPTION
  37. WHEN HIVE_EXCEPTION THEN
  38. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  39. WHEN Others THEN
  40. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  41. END;