客户信息.sql 8.2 KB

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