customertotaltemp.sql 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.customertotaltemp() IS
  2. DECLARE
  3. BEGIN
  4. DELETE FROM shanglifeecif.customertotaltemp;
  5. insert into shanglifeecif.customertotaltemp(
  6. scustid,
  7. name,
  8. gender,
  9. birthday,
  10. idcard,
  11. idtype
  12. )
  13. SELECT
  14. scustid ,
  15. max(name) as name,
  16. max(gender) as gender ,
  17. to_char(max(birthday),"yyyy-MM-dd") birthday,
  18. max(idcard) as idcard,
  19. max(idtype) AS idtype
  20. FROM (
  21. SELECT
  22. trim(customerno) AS scustid,--投保人
  23. trim(name) AS name,
  24. trim(sex) AS gender,
  25. trim(birthday) AS birthday,
  26. trim(idtype) AS idtype ,
  27. trim(idno) AS idcard
  28. FROM
  29. dsj.policy_information
  30. WHERE customerno IS NOT NULL
  31. UNION
  32. SELECT
  33. trim(insuredno) AS scustid,--被保人
  34. trim(insuredname) AS name,
  35. trim(insuredsex) AS gender,
  36. trim(insuredbirthday) AS birthday,
  37. trim(insuredidtype) AS idtype ,
  38. trim(insuredidno) AS idcard
  39. FROM
  40. dsj.policy_information
  41. WHERE insuredno IS NOT NULL
  42. ) tmpTable GROUP BY scustid;
  43. UPDATE shanglifeecif.customertotaltemp sct SET sct.mobile = (SELECT trim(t.MOBILE) FROM dsj.t_customer_class t WHERE sct.scustid=t.customer_id);
  44. dbms_output.put_line('customertotaltemp函数跑批完成!');
  45. EXCEPTION
  46. WHEN HIVE_EXCEPTION THEN
  47. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  48. WHEN Others THEN
  49. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  50. END ;