effective_customer.sql 1008 B

123456789101112131415161718192021222324252627
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.effective_customer() -- 创建主存储过程
  2. IS
  3. DECLARE
  4. scount int
  5. BEGIN
  6. DELETE FROM shanglifeecif.effectivecustomer WHERE fadateY = to_char(SYSDATE,"yyyy");
  7. INSERT INTO shanglifeecif.effectivecustomer(
  8. esid,
  9. fadateY,
  10. custclass,
  11. cnum
  12. )
  13. SELECT
  14. to_char(SYSDATE,"yyyy")||si.custclass,
  15. to_char(SYSDATE,"yyyy"),
  16. si.custclass,
  17. count(*) AS cnum
  18. FROM
  19. shanglifeecif.individual si WHERE si.Label91 IS NULL AND si.custclass IS NOT NULL AND si.custclass <> '0' GROUP BY si.custclass;
  20. dbms_output.put_line('effective_customer函数跑批完成!');
  21. EXCEPTION
  22. WHEN HIVE_EXCEPTION THEN
  23. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  24. WHEN Others THEN
  25. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  26. END;