客户信息koucx.sql 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. --初始化个人信息
  2. CREATE OR REPLACE PROCEDURE shanglifeecif.initIndividual() IS
  3. DECLARE
  4. indidcount INT;
  5. BEGIN
  6. --清空数据
  7. DELETE FROM shanglifeecif.individual;
  8. indidcount :=1;
  9. --初始化非本人身份证客户信息
  10. INSERT INTO shanglifeecif.individual(
  11. indid,
  12. CustID,
  13. scustid,
  14. name,
  15. gender,
  16. birthday,
  17. idcard,
  18. Passport,
  19. Dlicense,
  20. CREATED_BY,
  21. CREATED_TIME)
  22. SELECT row_number()over(),"CP" || lpad(row_number()over(),9,'0'),pi.CUSTOMERNO,pi.NAME,pi.SEX,to_char(pi.BIRTHDAY,'yyyy-MM-dd HH:mm:ss'),pi.idcard,pi.Passport,pi.Dlicense,'koucx',sysdate() FROM(
  23. SELECT CUSTOMERNO,NAME,SEX,BIRTHDAY,
  24. max(CASE IDTYPE WHEN '0' THEN IDNO ELSE null END) idcard,
  25. max(CASE IDTYPE WHEN '1' THEN IDNO ELSE NULL END) Passport,
  26. max(CASE IDTYPE WHEN '3' THEN IDNO ELSE NULL END) Dlicense
  27. FROM shanghailifeecif.policy_information WHERE IDNO IS NOT NULL GROUP BY CUSTOMERNO,NAME,SEX,BIRTHDAY,IDTYPE,IDNO
  28. UNION
  29. SELECT INSUREDNO AS CUSTOMERNO,INSUREDNAME AS NAME,INSUREDSEX AS SEX,INSUREDBIRTHDAY AS BIRTHDAY,
  30. max(CASE INSUREDIDTYPE WHEN '0' THEN insuredidno ELSE null END) idcard,
  31. max(CASE INSUREDIDTYPE WHEN '1' THEN insuredidno ELSE NULL END) Passport,
  32. max(CASE INSUREDIDTYPE WHEN '3' THEN insuredidno ELSE NULL END) Dlicense
  33. FROM shanghailifeecif.policy_information WHERE INSUREDIDNO IS NOT NULL GROUP BY INSUREDNO,INSUREDNAME,INSUREDSEX,INSUREDBIRTHDAY,INSUREDIDTYPE,insuredidno
  34. ) AS pi;
  35. /*SELECT count(*) INTO indidcount FROM shanglifeecif.individual;
  36. --初始化非本人护照客户信息
  37. INSERT INTO shanglifeecif.individual(
  38. indid,
  39. CustID,
  40. scustid,
  41. name,
  42. gender,
  43. birthday,
  44. Passport,
  45. CREATED_BY,
  46. CREATED_TIME)
  47. SELECT row_number()over()+indidcount+1,"CP" || lpad(row_number()over()+indidcount,9,'0'),pi.CUSTOMERNO,pi.NAME,pi.SEX,to_char(pi.BIRTHDAY,'yyyy-MM-dd HH:mm:ss'),pi.IDNO,'koucx',sysdate() FROM(
  48. SELECT CUSTOMERNO,NAME,SEX,BIRTHDAY,IDTYPE,IDNO FROM shanghailifeecif.policy_information WHERE IDNO IS NOT NULL AND IDTYPE = 1 AND RELATIONTOAPPNT<>'本人' GROUP BY CUSTOMERNO,NAME,SEX,BIRTHDAY,IDTYPE,IDNO
  49. UNION
  50. SELECT INSUREDNO AS CUSTOMERNO,INSUREDNAME AS NAME,INSUREDSEX AS SEX,INSUREDBIRTHDAY AS BIRTHDAY,INSUREDIDTYPE AS IDTYPE,insuredidno AS IDNO FROM shanghailifeecif.policy_information WHERE INSUREDIDNO IS NOT NULL AND INSUREDIDTYPE = 1 AND RELATIONTOAPPNT<>'本人' GROUP BY INSUREDNO,INSUREDNAME,INSUREDSEX,INSUREDBIRTHDAY,INSUREDIDTYPE,insuredidno
  51. ) AS pi;
  52. SELECT count(*) INTO indidcount FROM shanglifeecif.individual;
  53. --初始化非本人驾驶证客户信息
  54. INSERT INTO shanglifeecif.individual(
  55. indid,
  56. CustID,
  57. scustid,
  58. name,
  59. gender,
  60. birthday,
  61. Dlicense,
  62. CREATED_BY,
  63. CREATED_TIME)
  64. SELECT row_number()over()+indidcount+1,"CP" || lpad(row_number()over()+indidcount,9,'0'),pi.CUSTOMERNO,pi.NAME,pi.SEX,to_char(pi.BIRTHDAY,'yyyy-MM-dd HH:mm:ss'),pi.IDNO,'koucx',sysdate() FROM(
  65. SELECT CUSTOMERNO,NAME,SEX,BIRTHDAY,
  66. max(CASE IDTYPE WHEN '0' THEN IDNO ELSE null END) idcard,
  67. max(CASE IDTYPE WHEN '1' THEN IDNO ELSE NULL END) Passport,
  68. max(CASE IDTYPE WHEN '3' THEN IDNO ELSE NULL END) Dlicense
  69. FROM shanghailifeecif.policy_information WHERE IDNO IS NOT NULL AND IDTYPE = 3 AND RELATIONTOAPPNT<>'本人' GROUP BY CUSTOMERNO,NAME,SEX,BIRTHDAY,IDTYPE,IDNO
  70. UNION
  71. SELECT INSUREDNO AS CUSTOMERNO,INSUREDNAME AS NAME,INSUREDSEX AS SEX,INSUREDBIRTHDAY AS BIRTHDAY,INSUREDIDTYPE AS IDTYPE,insuredidno AS IDNO FROM shanghailifeecif.policy_information WHERE INSUREDIDNO IS NOT NULL AND INSUREDIDTYPE = 3 AND RELATIONTOAPPNT<>'本人' GROUP BY INSUREDNO,INSUREDNAME,INSUREDSEX,INSUREDBIRTHDAY,INSUREDIDTYPE,insuredidno
  72. ) AS pi;
  73. SELECT count(*) INTO indidcount FROM shanglifeecif.individual;
  74. --初始化单独处理本人客户信息
  75. INSERT INTO shanglifeecif.individual(
  76. indid,
  77. CustID,
  78. scustid,
  79. name,
  80. gender,
  81. birthday,
  82. idcard,
  83. Passport,
  84. Dlicense,
  85. CREATED_BY,
  86. CREATED_TIME)
  87. SELECT row_number()over()+indidcount+1,"CP" || lpad(row_number()over()+indidcount,9,'0'),pi.CUSTOMERNO,pi.NAME,pi.SEX,to_char(pi.BIRTHDAY,'yyyy-MM-dd HH:mm:ss'),pi.idcard,pi.Passport,pi.Dlicense,'koucx',sysdate() FROM(
  88. SELECT CUSTOMERNO,NAME,SEX,BIRTHDAY,
  89. max(CASE IDTYPE WHEN '0' THEN IDNO ELSE CASE INSUREDIDTYPE WHEN '0' THEN insuredidno ELSE null END END) idcard,
  90. max(CASE IDTYPE WHEN '1' THEN IDNO ELSE CASE INSUREDIDTYPE WHEN '1' THEN insuredidno ELSE NULL END END) Passport,
  91. max(CASE IDTYPE WHEN '3' THEN IDNO ELSE CASE INSUREDIDTYPE WHEN '3' THEN insuredidno ELSE NULL END END) Dlicense
  92. FROM shanghailifeecif.policy_information WHERE IDNO IS NOT NULL AND RELATIONTOAPPNT ='本人' GROUP BY CUSTOMERNO,NAME,SEX,BIRTHDAY,IDTYPE,IDNO
  93. ) AS pi;*/
  94. EXCEPTION
  95. WHEN HIVE_EXCEPTION THEN
  96. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  97. WHEN Others THEN
  98. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  99. END ;