客户信息存储过程.sql 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.init_individual_main() -- 初始化 数据全部插入
  2. IS
  3. DECLARE
  4. individual_count int
  5. strsql string
  6. BEGIN
  7. --先验是否一个客户id有多条记录对应不通的证件类别
  8. --初始化 身份证 用户
  9. shanglifeecif.init_individual_0(individual_count);
  10. --初始化 护照用户
  11. individual_count:=individual_count+1;
  12. shanglifeecif.init_individual_1(individual_count);
  13. --初始化 驾照用户
  14. individual_count:=individual_count+1;
  15. shanglifeecif.init_individual_3(individual_count);
  16. --其他 证件类型用户
  17. individual_count:=individual_count+1;
  18. shanglifeecif.init_individual_other(individual_count);
  19. --更新用户等级信息
  20. shanglifeecif.up_t_customers_class_1();
  21. --更新职业信息
  22. --shanglifeecif.up_health_insurance_listing_1();
  23. --更新其它信息
  24. shanglifeecif.up_other_customerinfo()
  25. END;
  26. /
  27. CREATE OR REPLACE PROCEDURE shanglifeecif.init_individual_0( individual_count OUT int) -- 初始化 身份证
  28. IS
  29. BEGIN
  30. --查询出此次处理的数据并出表中
  31. insert into shanglifeecif.individual (
  32. indid,
  33. custid,
  34. scustid,
  35. name,
  36. gender,
  37. birthday,
  38. idcard,
  39. created_time,
  40. created_by
  41. )
  42. SELECT
  43. row_number()over(),
  44. 'CP'||lpad(row_number()over(),10,'0'),
  45. scustid ,
  46. max(name) as name,
  47. max(gender) as gender ,
  48. max(birthday) as birthday,
  49. max(idcard) as idcard,
  50. sysdate,
  51. 'admin'
  52. FROM (
  53. SELECT
  54. trim(customerno) AS scustid,--投保人
  55. trim(name) AS name,
  56. trim(sex) AS gender,
  57. trim(birthday) AS birthday,
  58. trim(idtype) AS idtype ,
  59. trim(idno) AS idcard
  60. FROM
  61. shanghailifeecif.policy_information
  62. WHERE customerno IS NOT NULL AND idtype=0
  63. UNION
  64. SELECT
  65. trim(insuredno) AS scustid,--被保人
  66. trim(insuredname) AS name,
  67. trim(insuredsex) AS gender,
  68. trim(insuredbirthday) AS birthday,
  69. trim(insuredidtype) AS idtype ,
  70. trim(insuredidno) AS idcard
  71. FROM
  72. shanghailifeecif.policy_information
  73. WHERE insuredno IS NOT NULL AND insuredidtype=0
  74. ) tmpTable GROUP BY scustid
  75. --已经存在的数据行数
  76. select count(0) into individual_count from shanglifeecif.individual
  77. END;
  78. /
  79. CREATE OR REPLACE PROCEDURE shanglifeecif.init_individual_1(individual_count INOUT int) -- 初始化 护照
  80. IS
  81. BEGIN
  82. --查询出此次处理的数据并出表中
  83. insert into shanglifeecif.individual (
  84. indid,
  85. custid,
  86. scustid,
  87. name,
  88. gender,
  89. birthday,
  90. passport,
  91. created_time,
  92. created_by
  93. )
  94. SELECT
  95. row_number()over(),
  96. 'CP'||lpad(row_number()over(),10,'0'),
  97. scustid ,
  98. max(name) as name,
  99. max(gender) as gender ,
  100. max(birthday) as birthday,
  101. max(idcard) as idcard,
  102. sysdate,
  103. 'admin'
  104. FROM (
  105. SELECT
  106. trim(customerno) AS scustid,--投保人
  107. trim(name) AS name,
  108. trim(sex) AS gender,
  109. trim(birthday) AS birthday,
  110. trim(idtype) AS idtype ,
  111. trim(idno) AS idcard
  112. FROM
  113. shanghailifeecif.policy_information
  114. WHERE customerno IS NOT NULL AND idtype=1
  115. UNION
  116. SELECT
  117. trim(insuredno) AS scustid,--被保人
  118. trim(insuredname) AS name,
  119. trim(insuredsex) AS gender,
  120. trim(insuredbirthday) AS birthday,
  121. trim(insuredidtype) AS idtype ,
  122. trim(insuredidno) AS idcard
  123. FROM
  124. shanghailifeecif.policy_information
  125. WHERE insuredno IS NOT NULL AND insuredidtype=1
  126. ) tmpTable GROUP BY scustid
  127. --已经存在的数据行数
  128. select count(0) into individual_count from shanglifeecif.individual
  129. END;
  130. /
  131. CREATE OR REPLACE PROCEDURE shanglifeecif.init_individual_3(individual_count INOUT int) -- 初始化 驾照
  132. IS
  133. BEGIN
  134. --查询出此次处理的数据并出表中
  135. insert into shanglifeecif.individual(
  136. indid,
  137. custid,
  138. scustid,
  139. name,
  140. gender,
  141. birthday,
  142. dlicense,
  143. created_time,
  144. created_by
  145. )
  146. SELECT
  147. row_number()over(),
  148. 'CP'||lpad(row_number()over(),10,'0'),
  149. scustid ,
  150. max(name) as name,
  151. max(gender) as gender ,
  152. max(birthday) as birthday,
  153. max(idcard) as idcard,
  154. sysdate,
  155. 'admin'
  156. FROM (
  157. SELECT
  158. trim(customerno) AS scustid,--投保人
  159. trim(name) AS name,
  160. trim(sex) AS gender,
  161. trim(birthday) AS birthday,
  162. trim(idtype) AS idtype ,
  163. trim(idno) AS idcard
  164. FROM
  165. shanghailifeecif.policy_information
  166. WHERE customerno IS NOT NULL AND idtype=3
  167. UNION
  168. SELECT
  169. trim(insuredno) AS scustid,--被保人
  170. trim(insuredname) AS name,
  171. trim(insuredsex) AS gender,
  172. trim(insuredbirthday) AS birthday,
  173. trim(insuredidtype) AS idtype ,
  174. trim(insuredidno) AS idcard
  175. FROM
  176. shanghailifeecif.policy_information
  177. WHERE insuredno IS NOT NULL AND insuredidtype=3
  178. ) tmpTable GROUP BY scustid
  179. --已经存在的数据行数
  180. select count(0) into individual_count from shanglifeecif.individual
  181. END;
  182. /
  183. CREATE OR REPLACE PROCEDURE shanglifeecif.init_individual_other(individual_count INOUT int) -- 初始化除了以上三种证件信息
  184. IS
  185. BEGIN
  186. --查询出此次处理的数据并出表中
  187. insert into shanglifeecif.individual(
  188. indid,
  189. custid,
  190. scustid,
  191. name,
  192. gender,
  193. birthday,
  194. otheridnumber,
  195. created_time,
  196. created_by
  197. )
  198. SELECT
  199. row_number()over(),
  200. 'CP'||lpad(row_number()over(),10,'0'),
  201. scustid ,
  202. max(name) as name,
  203. max(gender) as gender ,
  204. max(birthday) as birthday,
  205. max(idcard) as idcard,
  206. sysdate,
  207. 'admin'
  208. FROM (
  209. SELECT
  210. trim(customerno) AS scustid,--投保人
  211. trim(name) AS name,
  212. trim(sex) AS gender,
  213. trim(birthday) AS birthday,
  214. trim(idtype) AS idtype ,
  215. trim(idno) AS idcard
  216. FROM
  217. shanghailifeecif.policy_information
  218. WHERE customerno IS NOT NULL AND idtype not in (0,1,3)
  219. UNION
  220. SELECT
  221. trim(insuredno) AS scustid,--被保人
  222. trim(insuredname) AS name,
  223. trim(insuredsex) AS gender,
  224. trim(insuredbirthday) AS birthday,
  225. trim(insuredidtype) AS idtype ,
  226. trim(insuredidno) AS idcard
  227. FROM
  228. shanghailifeecif.policy_information
  229. WHERE insuredno IS NOT NULL AND insuredidtype not in (0,1,3)
  230. ) tmpTable GROUP BY scustid
  231. --已经存在的数据行数
  232. select count(0) into individual_count from shanglifeecif.individual
  233. END;
  234. /
  235. CREATE OR REPLACE PROCEDURE shanglifeecif.up_t_customers_class_1() -- 创建存储过程
  236. IS
  237. BEGIN
  238. UPDATE shanglifeecif.individual a SET (
  239. CustClass ,-- 客户等级
  240. ConValue ,-- 贡献度分
  241. Awarded3 ,-- 家庭加分2
  242. Awarded2 ,-- 续期加分
  243. Awarded1 ,-- 保单加分
  244. SOValue ,-- 总分值
  245. EndDate, -- 客户等级失效日期
  246. Height, --身高
  247. Weight, --体重
  248. BMI,
  249. PIncome, --个人年收入
  250. FIncome, --家庭年收入
  251. IncomeSource, --收入来源
  252. SIStatus, --社保情况
  253. Ethnic, --民族情况
  254. Nation, --国籍
  255. MaritalStat, --婚姻
  256. Employer,--工作单位
  257. Education,--学历
  258. Dday, --死亡日期
  259. regtype, --户籍类型
  260. ZIPCODE,--邮编
  261. HPhone,--电话
  262. PMPhone,--手机
  263. email, -- 邮箱
  264. RAL --联系地址
  265. ) = (
  266. select
  267. b.CLASS_VALUE,--客户等级
  268. b.CONTRIBUTION_VALUE,--贡献度分
  269. b.AWARDED3, --家庭加分
  270. b.AWARDED2, --续期加分
  271. b.AWARDED1, --保单加分
  272. b.TOTAL_VALUE, --总分值
  273. trim(b.END_DATE) as END_DATE, --失效日期
  274. b.STATURE, --身高
  275. b.AVOIRDUPOIS,--体重
  276. b.BMI, --根据身高体重计算
  277. b.YEARINCOME, --个人年收入
  278. b.FAMILYYEARSALARY, --家庭年收入
  279. trim(b.INCOMESOURCE) as INCOMESOURCE, --收入来源
  280. trim(b.SOCIALINSUFLAG) as SOCIALINSUFLAG, --社保情况
  281. trim(b.NATIONALITY) as NATIONALITY, --民族情况
  282. trim(b.NATIVEPLACE) as NATIVEPLACE, --国籍
  283. trim(b.MARRIAGE) as MARRIAGE,--婚姻
  284. trim(b.GRPNAME) as GRPNAME,--工作单位名称
  285. trim(b.DEGREE) as DEGREE,--学历
  286. trim(b.DEATHDATE) as DEATHDATE,--死亡日期
  287. trim(b.DENTYPE) as DENTYPE,--户籍类型
  288. trim(b.ZIPCODE) as ZIPCODE,--邮编
  289. trim(b.PHONE) as PHONE,--电话
  290. trim(b.MOBILE) as MOBILE,--手机
  291. trim(b.EMAIL) as EMAIL,--邮箱
  292. trim(b.POSTALADDRESS) as POSTALADDRESS --联系地址
  293. from shanghailifeecif.t_customer_class b
  294. where b.CUSTOMER_ID = a.scustid
  295. ) WHERE 1=1 ;
  296. END;
  297. /
  298. CREATE OR REPLACE PROCEDURE shanglifeecif.up_other_customerinfo() -- 创建存储过程
  299. IS
  300. BEGIN
  301. --更新客户类型投保人
  302. UPDATE shanglifeecif.individual i SET i.custtype = '投保人' WHERE
  303. i.scustid IN (SELECT p.customerno FROM shanghailifeecif.policy_information p);
  304. --更新客户类型投保人、被保人
  305. UPDATE shanglifeecif.individual i SET i.custtype = '被保人' WHERE
  306. i.scustid IN (SELECT pi.insuredno FROM shanghailifeecif.policy_information pi);
  307. --更新客户类型投保人、被保人
  308. UPDATE shanglifeecif.individual i SET i.custtype = '投保人、被保人' WHERE
  309. i.scustid IN (SELECT p.customerno FROM shanghailifeecif.policy_information p)
  310. AND i.scustid IN (SELECT pi.insuredno FROM shanghailifeecif.policy_information pi);
  311. --更新业绩归属
  312. UPDATE shanglifeecif.Individual si1 SET si1.policybelong = (
  313. SELECT trim(t.SALECOM) FROM (
  314. SELECT row_number()OVER(PARTITION BY p.customerno ORDER BY p.CUSTOMGETPOLDATE desc) rd,p.customerno,p.SALECOM FROM shanghailifeecif.policy_information p
  315. ) t WHERE t.rd = 1 AND si1.scustid = t.customerno
  316. )
  317. UPDATE shanglifeecif.Individual si1 SET si1.policybelong = (
  318. SELECT trim(t.SALECOM) FROM (
  319. SELECT row_number()OVER(PARTITION BY p.insuredno ORDER BY p.CUSTOMGETPOLDATE desc) rd,p.insuredno,p.SALECOM FROM shanghailifeecif.policy_information p
  320. ) t WHERE t.rd = 1 AND si1.scustid = t.insuredno
  321. )
  322. END;
  323. /
  324. /*
  325. CREATE OR REPLACE PROCEDURE shanglifeecif.up_health_insurance_listing_1() -- 创建存储过程
  326. IS
  327. BEGIN
  328. --更新个人信息表
  329. UPDATE shanglifeecif.individual a SET (
  330. OccupationId ,-- 职业代码
  331. Occupation, -- 职业名称
  332. HomeAdress
  333. ) = (
  334. SELECT
  335. t.appntoccupationcode,
  336. t.appntoccupationname,
  337. t.APPNTHOMEADDRESS
  338. FROM (
  339. select
  340. appntno,
  341. max(appntoccupationcode) appntoccupationcode,--职业代码
  342. max(appntoccupationname) appntoccupationname,--职业名称
  343. max(APPNTHOMEADDRESS) APPNTHOMEADDRESS --住址
  344. from shanghailifeecif.HEALTH_INSURANCE_LISTING
  345. WHERE appntoccupationcode is not null
  346. and appntoccupationname is not NULL
  347. group by appntno
  348. ) t WHERE t.appntno = a.scustid
  349. );
  350. END;
  351. */
  352. BEGIN
  353. shanglifeecif.init_individual_main();
  354. end ;