riskcode_statistics.sql 1.0 KB

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