riskcode_statistics_channel.sql 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.riskcode_statistics_channel() IS
  2. DECLARE
  3. BEGIN
  4. DELETE FROM shanglifeecif.riskcode_statistics_channel;
  5. insert into shanglifeecif.riskcode_statistics_channel (
  6. id,
  7. kindName,
  8. khnum,
  9. tatolprem,
  10. salecom,
  11. salecomname
  12. ) --险种大类统计
  13. SELECT
  14. row_number()over(),
  15. temp.kindName,
  16. temp.khnum,
  17. temp.tatolprem,
  18. temp.salecom,
  19. temp.salecomname
  20. FROM (
  21. SELECT
  22. crt.riskcategoriesname AS kindName,
  23. count(DISTINCT scustid) AS khnum,
  24. sum(risk) AS tatolprem,
  25. crt.salecom AS salecom,
  26. crt.salecomname AS salecomname
  27. FROM shanglifeecif.customer_risk_temp crt
  28. WHERE crt.riskcategoriesname IS NOT null
  29. and crt.salecom is not null
  30. GROUP BY crt.riskcategoriesname,crt.salecom,crt.salecomname
  31. ) temp;
  32. dbms_output.put_line('riskcode_statistics_channel函数跑批完成!');
  33. EXCEPTION
  34. WHEN HIVE_EXCEPTION THEN
  35. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  36. WHEN Others THEN
  37. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  38. END ;