same_customer.sql 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.same_customer() -- 创建主存储过程
  2. IS
  3. DECLARE
  4. scount int
  5. BEGIN
  6. DELETE FROM shanglifeecif.samecustomer;
  7. INSERT INTO shanglifeecif.samecustomer(
  8. sid,
  9. scustid,
  10. name,
  11. gender,
  12. birthday,
  13. idcard,
  14. Passport,
  15. Dlicense,
  16. OtherIdNumber,
  17. sameType
  18. )
  19. SELECT
  20. reflect("java.util.UUID", "randomUUID"),
  21. sc1.scustid,
  22. sc1.name,
  23. sc1.gender,
  24. sc1.birthday,
  25. CASE sc1.idtype WHEN '0' THEN sc1.idcard END AS idcard,
  26. CASE sc1.idtype WHEN '1' THEN sc1.idcard END AS passport,
  27. CASE sc1.idtype WHEN '3' THEN sc1.idcard END AS dlicense,
  28. CASE WHEN sc1.idtype <> '0' AND sc1.idtype <> '1' AND sc1.idtype <> '3' THEN sc1.idcard END AS otherIdnumber,
  29. 0
  30. FROM shanglifeecif.customertotaltemp sc1
  31. WHERE sc1.mobile IS NOT NULL AND EXISTS (SELECT 1 FROM shanglifeecif.customertotaltemp sc2 WHERE sc1.scustid != sc2.scustid
  32. AND sc1.name = sc2.name AND sc1.gender = sc2.gender AND sc1.idtype = sc2.idtype AND sc1.mobile = sc2.mobile);
  33. --三要素疑似相同指姓名、性别、出生日期一致 1
  34. INSERT INTO shanglifeecif.samecustomer(
  35. sid,
  36. scustid,
  37. name,
  38. gender,
  39. birthday,
  40. idcard,
  41. Passport,
  42. Dlicense,
  43. OtherIdNumber,
  44. sameType
  45. )
  46. SELECT
  47. reflect("java.util.UUID", "randomUUID"),
  48. sc1.scustid,
  49. sc1.name,
  50. sc1.gender,
  51. sc1.birthday,
  52. CASE sc1.idtype WHEN '0' THEN sc1.idcard END AS idcard,
  53. CASE sc1.idtype WHEN '1' THEN sc1.idcard END AS passport,
  54. CASE sc1.idtype WHEN '3' THEN sc1.idcard END AS dlicense,
  55. CASE WHEN sc1.idtype <> '0' AND sc1.idtype <> '1' AND sc1.idtype <> '3' THEN sc1.idcard END AS otherIdnumber,
  56. 1
  57. FROM shanglifeecif.customertotaltemp sc1
  58. WHERE EXISTS(SELECT 1 FROM shanglifeecif.customertotaltemp sc2 WHERE sc2.scustid!=sc1.scustid AND sc1.name = sc2.name AND sc1.gender = sc2.gender AND sc1.birthday = sc2.birthday )
  59. ORDER BY sc1.name,sc1.gender,sc1.birthday
  60. --两要素疑似相同指姓名、证件号码一致 2
  61. INSERT INTO shanglifeecif.samecustomer(
  62. sid,
  63. scustid,
  64. name,
  65. gender,
  66. birthday,
  67. idcard,
  68. Passport,
  69. Dlicense,
  70. OtherIdNumber,
  71. sameType
  72. )
  73. SELECT
  74. reflect("java.util.UUID", "randomUUID"),
  75. sc1.scustid,
  76. sc1.name,
  77. sc1.gender,
  78. sc1.birthday,
  79. CASE sc1.idtype WHEN '0' THEN sc1.idcard END AS idcard,
  80. CASE sc1.idtype WHEN '1' THEN sc1.idcard END AS passport,
  81. CASE sc1.idtype WHEN '3' THEN sc1.idcard END AS dlicense,
  82. CASE WHEN sc1.idtype <> '0' AND sc1.idtype <> '1' AND sc1.idtype <> '3' THEN sc1.idcard END AS otherIdnumber,
  83. 2
  84. FROM shanglifeecif.customertotaltemp sc1
  85. WHERE sc1.idcard is not null and EXISTS (SELECT 1 FROM shanglifeecif.customertotaltemp sc2 WHERE sc2.scustid!=sc1.scustid AND sc1.name = sc2.name AND sc1.idcard = sc2.idcard);
  86. dbms_output.put_line('same_customer函数跑批完成!');
  87. END;