bdnum_distribution_channel.sql 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.bdnum_distribution_channel() IS
  2. DECLARE
  3. BEGIN
  4. --第一步 更新 Individual.NOVPolicy 有效记录数
  5. UPDATE shanglifeecif.Individual si1 SET si1.NOVPolicy = (SELECT nvl(t.cnum,0) FROM (
  6. SELECT temp.customerno,count(*) AS cnum FROM (
  7. SELECT max(p.customerno) customerno,p.contno FROM dsj.policy_information p WHERE p.appflag = '有效' GROUP BY p.contno
  8. ) temp GROUP BY temp.customerno
  9. ) t WHERE t.customerno = si1.scustid);
  10. --第二步 更新 Individual.NOIVPolicy 无效记录数
  11. UPDATE shanglifeecif.Individual si1 SET si1.noivpolicy = (SELECT nvl(t.cnum,0) FROM (
  12. SELECT temp.customerno,count(*) AS cnum FROM (
  13. SELECT max(p.customerno) customerno,p.contno FROM dsj.policy_information p WHERE p.appflag <> '有效' GROUP BY p.contno
  14. ) temp GROUP BY temp.customerno
  15. ) t WHERE t.customerno = si1.scustid);
  16. --第三步
  17. UPDATE shanglifeecif.Individual si1 SET si1.Label25 = (
  18. CASE
  19. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 0 THEN '无保单'
  20. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 1 THEN '1件保单'
  21. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) == 2 THEN '2件保单'
  22. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 3 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 5 THEN '3-5件保单'
  23. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 6 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 10 THEN '6-10件保单'
  24. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 11 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0))<= 20 THEN '11-20件保单'
  25. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) >= 21 AND (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) <= 50 THEN '21-50件保单'
  26. WHEN (nvl(si1.NOVPolicy,0) + nvl(si1.NOIVPolicy,0)) > 50 THEN '50件保单以上'
  27. END
  28. ) where si1.custtype like '%投保人%';
  29. DELETE FROM shanglifeecif.bdnum_distribution_channel;
  30. insert into shanglifeecif.bdnum_distribution_channel (
  31. id,
  32. labelName,
  33. bdnum
  34. ) SELECT row_number()over(),t.labelName,t.bdnum FROM (
  35. SELECT si.label25 labelName,count(1) bdnum FROM shanglifeecif.individual si WHERE si.label25 IS NOT null GROUP BY si.label25
  36. ) t;
  37. dbms_output.put_line('bdnum_distribution_channel函数跑批完成!');
  38. EXCEPTION
  39. WHEN HIVE_EXCEPTION THEN
  40. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  41. WHEN Others THEN
  42. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  43. END ;