个人信息开发qxp.sql 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  1. -----------------------------------------------------------------------
  2. --创建数据源
  3. CREATE TABLE policy_information(
  4. contno varchar2(200) DEFAULT NULL COMMENT '保单号', -- dialect: ORACLE
  5. riskcode varchar2(200) DEFAULT NULL COMMENT '险种代码', -- dialect: ORACLE
  6. riskname varchar2(200) DEFAULT NULL COMMENT '险种名称', -- dialect: ORACLE
  7. riskperiod varchar2(200) DEFAULT NULL COMMENT '险种分类', -- dialect: ORACLE
  8. risktype varchar2(200) DEFAULT NULL COMMENT '险种设计类型',
  9. payintv varchar2(200) DEFAULT NULL COMMENT '缴费方式',
  10. security varchar2(200) not NULL COMMENT '保障年期',
  11. payendyear number not NULL COMMENT '缴费期间',
  12. payendyearflag varchar2(200) not NULL COMMENT '缴费年期单位',
  13. insuyer number not NULL COMMENT '保险年期',
  14. insuyerflag varchar2(200) not NULL COMMENT '保险年期单位',
  15. paycount number not NULL COMMENT '续保次数',
  16. signdate timestamp not NULL COMMENT '承保日期',
  17. cvalidate timestamp not NULL COMMENT '生效日期',
  18. enddate timestamp not NULL COMMENT '保单终止日期',
  19. modifydate timestamp not null comment '更新时间',
  20. prem number not null COMMENT '保费',
  21. appflag varchar2(200) not NULL COMMENT '保单状态',
  22. customerno varchar2(200) not null comment '客户号',
  23. name varchar2(200) not null comment '客户姓名',
  24. sex varchar2(200) not null comment '客户性别',
  25. birthday timestamp not null comment '客户出生日期',
  26. idtype varchar2(200) not null comment '客户证件类型',
  27. idno varchar2(200) not null comment '客户证件号',
  28. insuredno varchar2(200) not null comment '被保人号',
  29. insuredname varchar2(200) not null comment '被保人姓名',
  30. insuredsex varchar2(200) not null comment '被保人性别',
  31. insuredbirthday timestamp not null comment '被保人出生日期',
  32. insuredidtype varchar2(200) not null comment '被保人证件类型',
  33. insuredidno varchar2(200) not null comment '被保人证件号码',
  34. relationtoappnt varchar2(200) not null comment '与投保人关系',
  35. salechnl varchar2(200) not null comment '销售渠道',
  36. salecom varchar2(200) not null comment '业绩归属',
  37. salechannels varchar2(200) not NULL COMMENT '二级业绩归属',
  38. customgetpoldate timestamp not null comment '客户投保日期',
  39. prem_js number not null comment 'prem_js'
  40. )
  41. COMMENT '投保清单'
  42. STORED AS CSVFILE ;
  43. --推送数据命令
  44. --hdfs dfs -put /home/frontData/ /tmp/myData/
  45. LOAD DATA INPATH '/tmp/myData/policy_information.txt' OVERWRITE INTO TABLE qxp.policy_information;
  46. --------------------------------------------------------------------------------------------------------------------
  47. TRUNCATE TABLE individual_search;
  48. --创建search目的表
  49. DROP TABLE IF EXISTS individual_search;
  50. CREATE TABLE qxp.individual_search(
  51. indid string DEFAULT NULL COMMENT '个体ID',
  52. custid string DEFAULT NULL COMMENT '全局客户号',
  53. SCustID string DEFAULT NULL COMMENT '客户号',
  54. created_by string DEFAULT NULL COMMENT '创建人',
  55. created_time timestamp DEFAULT NULL COMMENT '创建时间',
  56. updated_by string DEFAULT NULL COMMENT '更新人',
  57. updated_time timestamp DEFAULT NULL COMMENT '更新时间',
  58. name string DEFAULT NULL COMMENT '名称',
  59. birthday date DEFAULT NULL COMMENT '出生日期',
  60. nobirth string DEFAULT NULL COMMENT '出生国家', -- dialect: ORACLE
  61. sobirth string DEFAULT NULL COMMENT '出生省份', -- dialect: ORACLE
  62. cobirth string DEFAULT NULL COMMENT '出生城市', -- dialect: ORACLE
  63. homeadress string DEFAULT NULL COMMENT '籍贯',
  64. dday date DEFAULT NULL COMMENT '死亡日期',
  65. gender string DEFAULT NULL COMMENT '性别', -- dialect: ORACLE
  66. ethnic string DEFAULT NULL COMMENT '民族', -- dialect: ORACLE
  67. nation string DEFAULT NULL COMMENT '国籍', -- dialect: ORACLE
  68. regresidence string DEFAULT NULL COMMENT '户口所在地',
  69. maritalstat string DEFAULT NULL COMMENT '婚姻状况', -- dialect: ORACLE
  70. maritalstatdate date DEFAULT NULL COMMENT '婚姻状况日期',
  71. offspring string DEFAULT NULL COMMENT '生育状况', -- dialect: ORACLE
  72. support string DEFAULT NULL COMMENT '赡养状况', -- dialect: ORACLE
  73. empstat string DEFAULT NULL COMMENT '就业状况', -- dialect: ORACLE
  74. empstatdate string DEFAULT NULL COMMENT '就业状况日期', -- dialect: ORACLE
  75. raid string DEFAULT NULL COMMENT '居住地址',
  76. ral string DEFAULT NULL COMMENT '居住地址不分段',
  77. al string DEFAULT NULL COMMENT '曾用地址不分段',
  78. coadress int DEFAULT NULL COMMENT '地址登录数量',
  79. pmphone string DEFAULT NULL COMMENT '常用手机',
  80. mhone string DEFAULT NULL COMMENT '曾用手机',
  81. sophone int DEFAULT NULL COMMENT '手机登录数量',
  82. height decimal(8,2) DEFAULT NULL COMMENT '身高',
  83. weight decimal(8,2) DEFAULT NULL COMMENT '体重',
  84. cillness string DEFAULT NULL COMMENT '当前疾病', -- dialect: ORACLE
  85. pillness string DEFAULT NULL COMMENT '曾患疾病', -- dialect: ORACLE
  86. bmi decimal(8,2) DEFAULT NULL COMMENT 'BMI体制指数',
  87. evadate date DEFAULT NULL COMMENT '健康评估日期',
  88. cohevaluation int DEFAULT NULL COMMENT '健康评估登录数量',
  89. hphone string DEFAULT NULL COMMENT '家庭电话',
  90. occupation string DEFAULT NULL COMMENT '职业', -- dialect: ORACLE
  91. odate date DEFAULT NULL COMMENT '职业时间',
  92. employer string DEFAULT NULL COMMENT '工作单位',
  93. wphone string DEFAULT NULL COMMENT '工作电话',
  94. empdate date DEFAULT NULL COMMENT '工作单位时间',
  95. idcard string DEFAULT NULL COMMENT '身份证',
  96. passport string DEFAULT NULL COMMENT '护照',
  97. dlicense string DEFAULT NULL COMMENT '驾驶证',
  98. education string DEFAULT NULL COMMENT '最高学历', -- dialect: ORACLE
  99. university string DEFAULT NULL COMMENT '毕业学校',
  100. edate date DEFAULT NULL COMMENT '学历时间',
  101. wechat string DEFAULT NULL COMMENT '微信',
  102. weibo string DEFAULT NULL COMMENT '微博',
  103. email string DEFAULT NULL COMMENT '邮箱',
  104. qq string DEFAULT NULL COMMENT 'QQ',
  105. tiktok string DEFAULT NULL COMMENT '抖音',
  106. saccount1 string DEFAULT NULL COMMENT '社交账号1',
  107. sa1cat string DEFAULT NULL COMMENT '社交账号1类别', -- dialect: ORACLE
  108. saccount2 string DEFAULT NULL COMMENT '社交账号2',
  109. sa2cat string DEFAULT NULL COMMENT '社交账号2类别', -- dialect: ORACLE
  110. ctype string DEFAULT NULL COMMENT '首选联系方式', -- dialect: ORACLE
  111. father string DEFAULT NULL COMMENT '父亲',
  112. mother string DEFAULT NULL COMMENT '母亲',
  113. mate string DEFAULT NULL COMMENT '配偶',
  114. child1 string DEFAULT NULL COMMENT '子女1',
  115. child2 string DEFAULT NULL COMMENT '子女2',
  116. cochild int DEFAULT NULL COMMENT '子女登录数量',
  117. fmhistory string DEFAULT NULL COMMENT '家族病史', -- dialect: ORACLE
  118. rpid string DEFAULT NULL COMMENT '房产',
  119. rpdescribe string DEFAULT NULL COMMENT '房产描述',
  120. corp int DEFAULT NULL COMMENT '房产登录数量',
  121. vid string DEFAULT NULL COMMENT '车辆',
  122. vdescribe string DEFAULT NULL COMMENT '车辆描述',
  123. covehicle int DEFAULT NULL COMMENT '车辆登录数量',
  124. anniversary1 date DEFAULT NULL COMMENT '纪念日1',
  125. a1describe string DEFAULT NULL COMMENT '纪念日1类型', -- dialect: ORACLE
  126. anniversary2 date DEFAULT NULL COMMENT '纪念日2',
  127. a2describe string DEFAULT NULL COMMENT '纪念日2类型', -- dialect: ORACLE
  128. soanniversary int DEFAULT NULL COMMENT '纪念日登录数量',
  129. custtype string DEFAULT NULL COMMENT '客户类型', -- dialect: ORACLE
  130. bankname string DEFAULT NULL COMMENT '开户银行', -- dialect: ORACLE
  131. tobankcard string DEFAULT NULL COMMENT '银行卡类型', -- dialect: ORACLE
  132. accname string DEFAULT NULL COMMENT '账户名',
  133. bankaccno string DEFAULT NULL COMMENT '银行帐号',
  134. cobaccount int DEFAULT NULL COMMENT '账户登录数量',
  135. sotlirisk decimal(32,8) DEFAULT NULL COMMENT '传统寿险种保额合计',
  136. soairisk decimal(32,8) DEFAULT NULL COMMENT '意外类险种保额合计',
  137. sosiirisk decimal(32,8) DEFAULT NULL COMMENT '重疾类险种保额合计',
  138. somcirisk decimal(32,8) DEFAULT NULL COMMENT '医疗费用类险种保额合计',
  139. someirisk decimal(32,8) DEFAULT NULL COMMENT '医疗补贴类险种保额合计',
  140. soefirisk decimal(32,8) DEFAULT NULL COMMENT '教育金类险种保额合计',
  141. sopirisk decimal(32,8) DEFAULT NULL COMMENT '养老金类险种保额合计',
  142. sowmirisk decimal(32,8) DEFAULT NULL COMMENT '财富管理险种保额合计',
  143. custclass int DEFAULT NULL COMMENT '客户等级',
  144. convalue int DEFAULT NULL COMMENT '贡献度分',
  145. awarded3 int DEFAULT NULL COMMENT '家庭加分',
  146. awarded2 int DEFAULT NULL COMMENT '续期加分',
  147. awarded1 int DEFAULT NULL COMMENT '保单加分',
  148. sovalue int DEFAULT NULL COMMENT '总分值',
  149. enddate date DEFAULT NULL COMMENT '客户等级失效日期',
  150. systemtag1 string DEFAULT NULL COMMENT '系统标签域1',
  151. systemtag2 string DEFAULT NULL COMMENT '系统标签域2',
  152. systemtag3 string DEFAULT NULL COMMENT '系统标签域3',
  153. cocommunication int DEFAULT NULL COMMENT '接触次数',
  154. lcdate date DEFAULT NULL COMMENT '最近接触时间',
  155. lctype string DEFAULT NULL COMMENT '最近接触类型', -- dialect: ORACLE
  156. cocomplaint int DEFAULT NULL COMMENT '投诉次数',
  157. lcptdate date DEFAULT NULL COMMENT '最近投诉时间',
  158. lcptreason string DEFAULT NULL COMMENT '最近投诉原因', -- dialect: ORACLE
  159. lcptlink string DEFAULT NULL COMMENT '最近投诉环节', -- dialect: ORACLE
  160. lcptresult string DEFAULT NULL COMMENT '最近投诉处理结果', -- dialect: ORACLE
  161. lcptduration decimal(8,2) DEFAULT NULL COMMENT '最近投诉处理时长',
  162. lcptperson string DEFAULT NULL COMMENT '最近投诉人', -- dialect: ORACLE
  163. soppremium decimal(32,8) DEFAULT NULL COMMENT '累计已缴保费',
  164. lappdate date DEFAULT NULL COMMENT '最近投保日期',
  165. cndate date DEFAULT NULL COMMENT '最近报案日期',
  166. cnstatus string DEFAULT NULL COMMENT '最近报案状态', -- dialect: ORACLE
  167. cocnotification int DEFAULT NULL COMMENT '报案登录数量',
  168. fadate date DEFAULT NULL COMMENT '首次投保日期',
  169. ladate date DEFAULT NULL COMMENT '最近投保日期',
  170. lpno string DEFAULT NULL COMMENT '最近保险单号',
  171. lpstate string DEFAULT NULL COMMENT '最近保单状态', -- dialect: ORACLE
  172. lpname string DEFAULT NULL COMMENT '最近投保险种名称',
  173. copolicy int DEFAULT NULL COMMENT '保单登录数量',
  174. iaccno1 string DEFAULT NULL COMMENT '保险账户1',
  175. iaccno2 string DEFAULT NULL COMMENT '保险账户2',
  176. iaccno3 string DEFAULT NULL COMMENT '保险账户3',
  177. soiaccount1 decimal(32,8) DEFAULT NULL COMMENT '保险账户1余额',
  178. soiaccount2 decimal(32,8) DEFAULT NULL COMMENT '保险账户2余额',
  179. soiaccount3 decimal(32,8) DEFAULT NULL COMMENT '保险账户3余额',
  180. coiaccount int DEFAULT NULL COMMENT '保险账户登录数量',
  181. Label1 string COMMENT 'Label1' ,
  182. Label2 string COMMENT 'Label2' ,
  183. Label3 string COMMENT 'Label3' ,
  184. Label4 string COMMENT 'Label4' ,
  185. Label5 string COMMENT 'Label5' ,
  186. Label6 string COMMENT 'Label6' ,
  187. Label7 string COMMENT 'Label7' ,
  188. Label8 string COMMENT 'Label8' ,
  189. Label9 string COMMENT 'Label9' ,
  190. Label10 string COMMENT 'Label10' ,
  191. Label11 string COMMENT 'Label11' ,
  192. Label12 string COMMENT 'Label12' ,
  193. Label13 string COMMENT 'Label13' ,
  194. Label14 string COMMENT 'Label14' ,
  195. Label15 string COMMENT 'Label15' ,
  196. Label16 string COMMENT 'Label16' ,
  197. Label17 string COMMENT 'Label17' ,
  198. Label18 string COMMENT 'Label18' ,
  199. Label19 string COMMENT 'Label19' ,
  200. Label20 string COMMENT 'Label20' ,
  201. Label21 string COMMENT 'Label21' ,
  202. Label22 string COMMENT 'Label22' ,
  203. Label23 string COMMENT 'Label23' ,
  204. Label24 string COMMENT 'Label24' ,
  205. Label25 string COMMENT 'Label25' ,
  206. Label26 string COMMENT 'Label26' ,
  207. Label27 string COMMENT 'Label27' ,
  208. Label28 string COMMENT 'Label28' ,
  209. Label29 string COMMENT 'Label29' ,
  210. Label30 string COMMENT 'Label30' ,
  211. Label31 string COMMENT 'Label31' ,
  212. Label32 string COMMENT 'Label32' ,
  213. Label33 string COMMENT 'Label33' ,
  214. Label34 string COMMENT 'Label34' ,
  215. Label35 string COMMENT 'Label35' ,
  216. Label36 string COMMENT 'Label36' ,
  217. Label37 string COMMENT 'Label37' ,
  218. Label38 string COMMENT 'Label38' ,
  219. Label39 string COMMENT 'Label39' ,
  220. Label40 string COMMENT 'Label40' ,
  221. Label41 string COMMENT 'Label41' ,
  222. Label42 string COMMENT 'Label42' ,
  223. Label43 string COMMENT 'Label43' ,
  224. Label44 string COMMENT 'Label44' ,
  225. Label45 string COMMENT 'Label45' ,
  226. Label46 string COMMENT 'Label46' ,
  227. Label47 string COMMENT 'Label47' ,
  228. Label48 string COMMENT 'Label48' ,
  229. Label49 string COMMENT 'Label49' ,
  230. Label50 string COMMENT 'Label50' ,
  231. Label51 string COMMENT 'Label51' ,
  232. Label52 string COMMENT 'Label52' ,
  233. Label53 string COMMENT 'Label53' ,
  234. Label54 string COMMENT 'Label54' ,
  235. Label55 string COMMENT 'Label55' ,
  236. Label56 string COMMENT 'Label56' ,
  237. Label57 string COMMENT 'Label57' ,
  238. Label58 string COMMENT 'Label58' ,
  239. Label59 string COMMENT 'Label59' ,
  240. Label60 string COMMENT 'Label60' ,
  241. Label61 string COMMENT 'Label61' ,
  242. Label62 string COMMENT 'Label62' ,
  243. Label63 string COMMENT 'Label63' ,
  244. Label64 string COMMENT 'Label64' ,
  245. Label65 string COMMENT 'Label65' ,
  246. Label66 string COMMENT 'Label66' ,
  247. Label67 string COMMENT 'Label67' ,
  248. Label68 string COMMENT 'Label68' ,
  249. Label69 string COMMENT 'Label69' ,
  250. Label70 string COMMENT 'Label70' ,
  251. Label71 string COMMENT 'Label71' ,
  252. Label72 string COMMENT 'Label72' ,
  253. Label73 string COMMENT 'Label73' ,
  254. Label74 string COMMENT 'Label74' ,
  255. Label75 string COMMENT 'Label75' ,
  256. Label76 string COMMENT 'Label76' ,
  257. Label77 string COMMENT 'Label77' ,
  258. Label78 string COMMENT 'Label78' ,
  259. Label79 string COMMENT 'Label79' ,
  260. Label80 string COMMENT 'Label80' ,
  261. Label81 string COMMENT 'Label81' ,
  262. Label82 string COMMENT 'Label82' ,
  263. Label83 string COMMENT 'Label83' ,
  264. Label84 string COMMENT 'Label84' ,
  265. Label85 string COMMENT 'Label85' ,
  266. Label86 string COMMENT 'Label86' ,
  267. Label87 string COMMENT 'Label87' ,
  268. Label88 string COMMENT 'Label88' ,
  269. Label89 string COMMENT 'Label89' ,
  270. Label90 string COMMENT 'Label90' ,
  271. Label91 string COMMENT 'Label91' ,
  272. Label92 string COMMENT 'Label92' ,
  273. Label93 string COMMENT 'Label93' ,
  274. Label94 string COMMENT 'Label94' ,
  275. Label95 string COMMENT 'Label95' ,
  276. Label96 string COMMENT 'Label96' ,
  277. Label97 string COMMENT 'Label97' ,
  278. Label98 string COMMENT 'Label98' ,
  279. Label99 string COMMENT 'Label99' ,
  280. Label100 string COMMENT 'Label100' ,
  281. Label101 string COMMENT 'Label101' ,
  282. Label102 string COMMENT 'Label102' ,
  283. Label103 string COMMENT 'Label103' ,
  284. Label104 string COMMENT 'Label104' ,
  285. Label105 string COMMENT 'Label105' ,
  286. Label106 string COMMENT 'Label106' ,
  287. Label107 string COMMENT 'Label107' ,
  288. Label108 string COMMENT 'Label108' ,
  289. Label109 string COMMENT 'Label109' ,
  290. Label110 string COMMENT 'Label110' ,
  291. Label111 string COMMENT 'Label111' ,
  292. Label112 string COMMENT 'Label112' ,
  293. Label113 string COMMENT 'Label113' ,
  294. Label114 string COMMENT 'Label114' ,
  295. Label115 string COMMENT 'Label115' ,
  296. Label116 string COMMENT 'Label116' ,
  297. Label117 string COMMENT 'Label117' ,
  298. Label118 string COMMENT 'Label118' ,
  299. Label119 string COMMENT 'Label119' ,
  300. Label120 string COMMENT 'Label120'
  301. )
  302. COMMENT '个人信息'
  303. STORED AS ES
  304. with shard number 10
  305. replication 1;
  306. ---------------------------------------------------------------------------------------、
  307. --创建 自增id
  308. --创建序列
  309. DROP SEQUENCE IF EXISTS globaleCusId_sequence;
  310. CREATE SEQUENCE globaleCusId_sequence
  311. INCREMENT BY 1
  312. START WITH 1
  313. NOMAXVALUE
  314. NOMINVALUE
  315. NOCYCLE
  316. CACHE 1;
  317. --------------------------------------------------------------------------------------------
  318. --创建存储过程 插入individual_search
  319. !set plsqlUseSlash true
  320. CREATE OR REPLACE PROCEDURE test_insert_individual_search_1() -- 创建存储过程
  321. IS
  322. DECLARE
  323. --五要素行变量
  324. TYPE main_columns_type IS RECORD (scustid string, name string,gender string,birthday timestamp,idtype int,idcard string)
  325. mainrecord main_columns_type
  326. --等级信息行变量
  327. t_record t_customer_class%ROWTYPE
  328. cnt int --判断目标数据库中是否有值
  329. cnt_t int --判断t_customer_class是否有值
  330. custid_tmp string
  331. CURSOR main_cursor IS
  332. --查询所有的人 根据5要素
  333. select scustid ,name,gender ,birthday,idtype,idcard
  334. from (
  335. SELECT
  336. CUSTOMERNO AS scustid,--投保人
  337. NAME AS name,
  338. sex AS gender,
  339. BIRTHDAY AS birthday,
  340. IDTYPE AS idtype ,
  341. IDNO AS idcard
  342. FROM
  343. policy_information
  344. UNION
  345. SELECT
  346. INSUREDNO AS scustid,--被保人
  347. INSUREDNAME AS name,
  348. INSUREDSEX AS gender,
  349. INSUREDBIRTHDAY AS birthday,
  350. INSUREDIDTYPE AS idtype ,
  351. INSUREDIDNO AS idcard
  352. FROM
  353. policy_information
  354. ) tmpTable
  355. WHERE scustid IS NOT NULL
  356. group by scustid ,name,gender ,birthday,idtype,idcard
  357. LIMIT 0,100;
  358. BEGIN
  359. -- 定义游标并输入结果集
  360. OPEN main_cursor; -- 打开游标
  361. LOOP -- 开始循环体,myLoop为自定义循环名,结束循环时用到
  362. FETCH main_cursor INTO mainrecord; -- 将游标当前读取行的数据顺序赋予自定义变量12
  363. --判断是否是身份证
  364. if mainrecord.idtype !=0 then
  365. mainrecord.idcard := null
  366. end if
  367. -- 判断是否添加
  368. select count(1) into cnt from individual_search where scustid = mainrecord.scustid and name = mainrecord.name and birthday = mainrecord.birthday
  369. and gender = mainrecord.gender and idcard = mainrecord.idcard
  370. if cnt ==0 then
  371. -- 生成 全局id
  372. custid_tmp:='CP'||lpad(globaleCusId_sequence.nextval,10,'0')
  373. --获取 等级信息
  374. select count(1) into cnt_t from t_customer_class where CUSTOMER_ID = mainrecord.scustid ;
  375. if cnt_t ==0 then
  376. t_record.CLASS_VALUE:=0; -- CustClass 客户等级
  377. t_record.CONTRIBUTION_VALUE:=0; -- ConValue 贡献度分
  378. t_record.Awarded3:=0; -- Awarded3 家庭加分
  379. t_record.AWARDED2:=0; -- Awarded2 续期加分
  380. t_record.AWARDED1:=0; -- Awarded1 保单加分
  381. t_record.TOTAL_VALUE:=0; -- SOValue 总分值
  382. t_record.end_date:=null; -- EndDate 客户等级失效日期
  383. else
  384. end if
  385. --插入数据
  386. Insert into individual_search(
  387. CREATED_BY ,-- 创建人
  388. CREATED_TIME ,-- 创建时间
  389. UPDATED_BY ,-- 更新人
  390. UPDATED_TIME ,-- 更新时间
  391. --IndID ,-- 个体ID
  392. CustID ,-- 客户号
  393. SCustID,--上游客户号
  394. Name ,-- 名称
  395. Birthday ,-- 出生日期
  396. Gender ,-- 性别
  397. IDCard ,-- 身份证
  398. CustClass ,-- 客户等级
  399. ConValue ,-- 贡献度分
  400. Awarded3 ,-- 家庭加分
  401. Awarded2 ,-- 续期加分
  402. Awarded1 ,-- 保单加分
  403. SOValue ,-- 总分值
  404. EndDate -- 客户等级失效日期
  405. )values(
  406. 'qxp' , -- CREATED_BY 创建人
  407. SYSDATE , -- CREATED_TIME 创建时间
  408. NULL , -- UPDATED_BY 更新人
  409. SYSDATE , -- UPDATED_TIME 更新时间
  410. --NULL, -- IndID 个体ID
  411. custid_tmp, --CustID 客户号
  412. mainrecord.scustid, -- sCustID 上游客户号
  413. mainrecord.Name, -- Name 名称
  414. mainrecord.Birthday, -- Birthday 出生日期
  415. mainrecord.gender, -- Gender 性别
  416. mainrecord.IDCard, -- IDCard 身份证
  417. t_record.CLASS_VALUE, -- CustClass 客户等级
  418. t_record.CONTRIBUTION_VALUE, -- ConValue 贡献度分
  419. t_record.Awarded3, -- Awarded3 家庭加分
  420. t_record.AWARDED2, -- Awarded2 续期加分
  421. t_record.AWARDED1, -- Awarded1 保单加分
  422. t_record.TOTAL_VALUE, -- SOValue 总分值
  423. t_record.end_date -- EndDate 客户等级失效日期
  424. )
  425. end if
  426. cnt :=0
  427. EXIT WHEN main_cursor%NOTFOUND
  428. END LOOP; -- 结束自定义循环体
  429. CLOSE main_cursor; -- 关闭游标
  430. END; -- 结束存储过
  431. ----------------------------------------------------------------------------------------------------------
  432. ----------------------------------------------------------------------------------------------------------
  433. ----------------------------------------------------------------------------------------------------------
  434. CREATE OR REPLACE PROCEDURE test_etl_main_1() -- 创建存储过程
  435. IS
  436. BEGIN
  437. test_insert_individual_search_2();--插入五要素
  438. test_up_t_customers_class_1();--更新用户等级等信息
  439. END;
  440. -----------------------------------------------------------------------------------
  441. --不用游标的做法
  442. --------------------------------------------------------------------------------------------
  443. --创建存储过程 插入individual_search
  444. !set plsqlUseSlash true
  445. SET plsql.catch.hive.exception=true; --使用HIVE_EXCEPTION捕获Hive异常
  446. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  447. CREATE OR REPLACE PROCEDURE test_insert_individual_search_2() -- 创建存储过程
  448. IS
  449. DECLARE
  450. BEGIN
  451. MERGE INTO individual_search is1 using
  452. (
  453. SELECT scustid ,name,gender ,birthday, idcard
  454. FROM (
  455. SELECT
  456. customerno AS scustid,--投保人
  457. name AS name,
  458. sex AS gender,
  459. birthday AS birthday,
  460. idtype AS idtype ,
  461. idno AS idcard
  462. FROM
  463. policy_information
  464. WHERE customerno IS NOT NULL AND idtype=0
  465. UNION
  466. SELECT
  467. insuredno AS scustid,--被保人
  468. insuredname AS name,
  469. insuredsex AS gender,
  470. insuredbirthday AS birthday,
  471. insuredidtype AS idtype ,
  472. insuredidno AS idcard
  473. FROM
  474. policy_information
  475. WHERE insuredno IS NOT NULL AND insuredidtype=0
  476. ) tmpTable
  477. LIMIT IN 0,100000
  478. ) is2 on (is2.scustid = is1.scustid and is2.name = is1.name
  479. and is2.gender = is1.gender and is2.birthday = is1.birthday and is2.idcard = is1.idcard)
  480. WHEN NOT MATCHED THEN INSERT (
  481. scustid,
  482. name,
  483. gender,
  484. birthday,
  485. idcard,
  486. custid,
  487. indid,
  488. created_time,
  489. created_by
  490. ) VALUES (
  491. is2.scustid,
  492. is2.name,
  493. is2.gender,
  494. is2.birthday,
  495. is2.idcard,
  496. 'CP'||lpad(globaleCusId_sequence.nextval,10,'0'),
  497. globaleCusId_sequence.CURRVAL,
  498. sysdate,
  499. 'qxp'
  500. )
  501. EXCEPTION
  502. WHEN HIVE_EXCEPTION THEN
  503. log_exception('test_insert_individual_search_2',sqlerrm(),sqlcode())
  504. WHEN Others THEN
  505. log_exception('test_insert_individual_search_2',sqlerrm(),sqlcode())
  506. END;
  507. --------------------------------------------------------------------------------------------
  508. --------------------------------------------------------------------------------------------
  509. -------------------------------------------------------------------------------------------
  510. -------------------------------------------------------------------------------------------
  511. =============================================================================================================================================================
  512. ==============================================================利用行号全部插入用户数据==========================================================================
  513. =============================================================================================================================================================
  514. --初始化存储过程
  515. -- 身份证 0
  516. -- 护照 1
  517. -- 军人证(军官证) 2
  518. -- 驾照 3
  519. -- 户口本 4
  520. -- 学生证 5
  521. -- 工作证 6
  522. -- 出生证 7
  523. -- 其它 8
  524. -- 无证件 9
  525. -- 士兵证 A
  526. -- 回乡证 B
  527. -- 临时身份证 C
  528. -- 警官证 D
  529. -- 台胞证 E
  530. -- 港、澳通行证 F
  531. -- 外国人永久居留身份证 I
  532. -- 港澳台居民居住证 J
  533. -- 港澳居民居住证 K
  534. -- 台湾居民居住证 M
  535. !set plsqlUseSlash true
  536. SET plsql.catch.hive.exception=true; --使用HIVE_EXCEPTION捕获Hive异常
  537. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  538. CREATE OR REPLACE PROCEDURE init_individual_search_main() -- 初始化 数据全部插入
  539. IS
  540. DECLARE
  541. individual_count int
  542. strsql string
  543. BEGIN
  544. --先验是否一个客户id有多条记录对应不通的证件类别
  545. --初始化 身份证 用户
  546. init_individual_search_0(individual_count);
  547. --初始化 护照用户
  548. individual_count:=individual_count+1;
  549. init_individual_search_1(individual_count);
  550. --初始化 驾照用户
  551. individual_count:=individual_count+1;
  552. init_individual_search_3(individual_count);
  553. --其他 证件类型用户
  554. individual_count:=individual_count+1;
  555. init_individual_search_other(individual_count);
  556. --初始化 全局序列
  557. individual_count:=individual_count+1;
  558. strsql:='
  559. DROP SEQUENCE IF EXISTS globaleCusId_sequence;
  560. CREATE SEQUENCE globaleCusId_sequence
  561. INCREMENT BY 1
  562. START WITH '|| individual_count||'
  563. NOMAXVALUE
  564. NOMINVALUE
  565. NOCYCLE
  566. CACHE 1;
  567. ';
  568. EXECUTE IMMEDIATE strsql
  569. --更新用户等级信息
  570. test_up_t_customers_class_1();
  571. --更新职业信息
  572. up_health_insurance_listing_1();
  573. EXCEPTION
  574. WHEN HIVE_EXCEPTION THEN
  575. log_exception('init_individual_search_main',sqlerrm(),sqlcode())
  576. WHEN Others THEN
  577. log_exception('init_individual_search_main',sqlerrm(),sqlcode())
  578. END;
  579. !set plsqlUseSlash true
  580. SET plsql.catch.hive.exception=true; --使用HIVE_EXCEPTION捕获Hive异常
  581. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  582. CREATE OR REPLACE PROCEDURE init_individual_search_0( individual_count OUT int) -- 初始化 省份证
  583. IS
  584. BEGIN
  585. --查询出此次处理的数据并出表中
  586. insert into individual_search1 (
  587. indid,
  588. custid,
  589. scustid,
  590. name,
  591. gender,
  592. birthday,
  593. idcard,
  594. created_time,
  595. created_by
  596. )
  597. SELECT
  598. row_number()over(),
  599. 'CP'||lpad(row_number()over(),10,'0'),
  600. scustid ,
  601. name,
  602. gender ,
  603. birthday,
  604. idcard ,
  605. sysdate,
  606. 'qxp'
  607. FROM (
  608. SELECT
  609. customerno AS scustid,--投保人
  610. name AS name,
  611. sex AS gender,
  612. birthday AS birthday,
  613. idtype AS idtype ,
  614. idno AS idcard
  615. FROM
  616. policy_information
  617. WHERE customerno IS NOT NULL AND idtype=0
  618. UNION
  619. SELECT
  620. insuredno AS scustid,--被保人
  621. insuredname AS name,
  622. insuredsex AS gender,
  623. insuredbirthday AS birthday,
  624. insuredidtype AS idtype ,
  625. insuredidno AS idcard
  626. FROM
  627. policy_information
  628. WHERE insuredno IS NOT NULL AND insuredidtype=0
  629. ) tmpTable
  630. --已经存在的数据行数
  631. select count(0) into individual_count from individual_search1
  632. EXCEPTION
  633. WHEN HIVE_EXCEPTION THEN
  634. log_exception('init_individual_search_0',sqlerrm(),sqlcode())
  635. WHEN Others THEN
  636. log_exception('init_individual_search_0',sqlerrm(),sqlcode())
  637. END;
  638. !set plsqlUseSlash true
  639. SET plsql.catch.hive.exception=true; --使用HIVE_EXCEPTION捕获Hive异常
  640. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  641. CREATE OR REPLACE PROCEDURE init_individual_search_1(individual_count INOUT int) -- 初始化 护照
  642. IS
  643. BEGIN
  644. --查询出此次处理的数据并出表中
  645. insert into individual_search1 (
  646. indid,
  647. custid,
  648. scustid,
  649. name,
  650. gender,
  651. birthday,
  652. passport,
  653. created_time,
  654. created_by
  655. )
  656. SELECT
  657. row_number()over()+individual_count,
  658. 'CP'||lpad(row_number()over()+individual_count,10,'0'),
  659. scustid ,
  660. name,
  661. gender ,
  662. birthday,
  663. idcard ,
  664. sysdate,
  665. 'qxp'
  666. FROM (
  667. SELECT
  668. customerno AS scustid,--投保人
  669. name AS name,
  670. sex AS gender,
  671. birthday AS birthday,
  672. idtype AS idtype ,
  673. idno AS idcard
  674. FROM
  675. policy_information
  676. WHERE customerno IS NOT NULL AND idtype=1
  677. UNION
  678. SELECT
  679. insuredno AS scustid,--被保人
  680. insuredname AS name,
  681. insuredsex AS gender,
  682. insuredbirthday AS birthday,
  683. insuredidtype AS idtype ,
  684. insuredidno AS idcard
  685. FROM
  686. policy_information
  687. WHERE insuredno IS NOT NULL AND insuredidtype=1
  688. ) tmpTable
  689. --已经存在的数据行数
  690. select count(0) into individual_count from individual_search1
  691. EXCEPTION
  692. WHEN HIVE_EXCEPTION THEN
  693. log_exception('init_individual_search_1',sqlerrm(),sqlcode())
  694. WHEN Others THEN
  695. log_exception('init_individual_search_1',sqlerrm(),sqlcode())
  696. END;
  697. !set plsqlUseSlash true
  698. SET plsql.catch.hive.exception=true; --使用HIVE_EXCEPTION捕获Hive异常
  699. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  700. CREATE OR REPLACE PROCEDURE init_individual_search_3(individual_count INOUT int) -- 初始化 护照
  701. IS
  702. BEGIN
  703. --查询出此次处理的数据并出表中
  704. insert into individual_search1(
  705. indid,
  706. custid,
  707. scustid,
  708. name,
  709. gender,
  710. birthday,
  711. dlicense,
  712. created_time,
  713. created_by
  714. )
  715. SELECT
  716. row_number()over()+individual_count,
  717. 'CP'||lpad(row_number()over()+individual_count,10,'0'),
  718. scustid ,
  719. name,
  720. gender ,
  721. birthday,
  722. idcard ,
  723. sysdate,
  724. 'qxp'
  725. FROM (
  726. SELECT
  727. customerno AS scustid,--投保人
  728. name AS name,
  729. sex AS gender,
  730. birthday AS birthday,
  731. idtype AS idtype ,
  732. idno AS idcard
  733. FROM
  734. policy_information
  735. WHERE customerno IS NOT NULL AND idtype=3
  736. UNION
  737. SELECT
  738. insuredno AS scustid,--被保人
  739. insuredname AS name,
  740. insuredsex AS gender,
  741. insuredbirthday AS birthday,
  742. insuredidtype AS idtype ,
  743. insuredidno AS idcard
  744. FROM
  745. policy_information
  746. WHERE insuredno IS NOT NULL AND insuredidtype=3
  747. ) tmpTable
  748. --已经存在的数据行数
  749. select count(0) into individual_count from individual_search1
  750. EXCEPTION
  751. WHEN HIVE_EXCEPTION THEN
  752. log_exception('init_individual_search_3',sqlerrm(),sqlcode())
  753. WHEN Others THEN
  754. log_exception('init_individual_search_3',sqlerrm(),sqlcode())
  755. END;
  756. !set plsqlUseSlash true
  757. SET plsql.catch.hive.exception=true; --使用HIVE_EXCEPTION捕获Hive异常
  758. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  759. CREATE OR REPLACE PROCEDURE init_individual_search_other(individual_count INOUT int) -- 初始化 护照
  760. IS
  761. BEGIN
  762. --查询出此次处理的数据并出表中
  763. insert into individual_search1(
  764. indid,
  765. custid,
  766. scustid,
  767. name,
  768. gender,
  769. birthday,
  770. created_time,
  771. created_by
  772. )
  773. SELECT
  774. row_number()over()+individual_count,
  775. 'CP'||lpad(row_number()over()+individual_count,10,'0'),
  776. scustid ,
  777. name,
  778. gender ,
  779. birthday,
  780. sysdate,
  781. 'qxp'
  782. FROM (
  783. SELECT
  784. customerno AS scustid,--投保人
  785. name AS name,
  786. sex AS gender,
  787. birthday AS birthday,
  788. idtype AS idtype ,
  789. idno AS idcard
  790. FROM
  791. policy_information
  792. WHERE customerno IS NOT NULL AND idtype not in (0,1,3)
  793. UNION
  794. SELECT
  795. insuredno AS scustid,--被保人
  796. insuredname AS name,
  797. insuredsex AS gender,
  798. insuredbirthday AS birthday,
  799. insuredidtype AS idtype ,
  800. insuredidno AS idcard
  801. FROM
  802. policy_information
  803. WHERE insuredno IS NOT NULL AND insuredidtype in (0,1,3)
  804. ) tmpTable
  805. --已经存在的数据行数
  806. select count(0) into individual_count from individual_search1
  807. EXCEPTION
  808. WHEN HIVE_EXCEPTION THEN
  809. log_exception('init_individual_search_other',sqlerrm(),sqlcode())
  810. WHEN Others THEN
  811. log_exception('init_individual_search_other',sqlerrm(),sqlcode())
  812. END;
  813. --创建存储过程 插入individual_search
  814. !set plsqlUseSlash true
  815. SET plsql.catch.hive.exception=true; --使用HIVE_EXCEPTION捕获Hive异常
  816. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  817. CREATE OR REPLACE PROCEDURE test_up_t_customers_class_1() -- 创建存储过程
  818. IS
  819. BEGIN
  820. UPDATE individual_search1 a SET (
  821. CustClass ,-- 客户等级
  822. ConValue ,-- 贡献度分
  823. Awarded3 ,-- 家庭加分
  824. Awarded2 ,-- 续期加分
  825. Awarded1 ,-- 保单加分
  826. SOValue ,-- 总分值
  827. EndDate -- 客户等级失效日期
  828. ) = (
  829. select
  830. CLASS_VALUE ,--客户等级
  831. CONTRIBUTION_VALUE ,--贡献度分
  832. AWARDED3, --家庭加分
  833. AWARDED2, --续期加分
  834. AWARDED1, --保单加分
  835. TOTAL_VALUE, --总分值
  836. END_DATE --失效日期
  837. from t_customer_class b
  838. where b.CUSTOMER_ID = a.scustid;
  839. ) WHERE 1=1 ;
  840. EXCEPTION
  841. WHEN HIVE_EXCEPTION THEN
  842. log_exception('test_up_t_customers_class_1',sqlerrm(),sqlcode())
  843. WHEN Others THEN
  844. log_exception('test_up_t_customers_class_1',sqlerrm(),sqlcode())
  845. END;
  846. /
  847. DROP TABLE IF EXISTS occupation_tmp;
  848. CREATE TABLE occupation_tmp(
  849. scustid string not NULL COMMENT '客户号',
  850. OccupationId string DEFAULT NULL COMMENT '名称',
  851. Occupation string DEFAULT NULL COMMENT '出生日期' ,
  852. HomeAdress string DEFAULT NULL COMMENT '籍贯'
  853. )
  854. COMMENT 'occupation_tmp 客户职业临时表' STORED AS ES
  855. with shard number 10
  856. replication 1;
  857. --根据HEALTH_INSURANCE_LISTING表更新
  858. CREATE OR REPLACE PROCEDURE up_health_insurance_listing_1() -- 创建存储过程
  859. IS
  860. BEGIN
  861. --清楚临时表数据
  862. delete occupation_tmp;
  863. --插入去重数据到临时表
  864. insert into occupation_tmp(
  865. scustid,
  866. OccupationId,
  867. Occupation,
  868. HomeAdress
  869. )
  870. select
  871. appntno,
  872. appntoccupationcode ,--职业代码
  873. appntoccupationname ,
  874. APPNTHOMEADDRESS--职业名称
  875. from HEALTH_INSURANCE_LISTING
  876. WHERE appntoccupationcode is not null
  877. and appntoccupationname is not null
  878. group by appntno,appntoccupationcode,appntoccupationname,APPNTHOMEADDRESS
  879. --更新个人信息表
  880. UPDATE individual_search1 a SET (
  881. OccupationId ,-- 职业代码
  882. Occupation, -- 职业名称
  883. HomeAdress
  884. ) = (
  885. select
  886. OccupationId ,--职业代码
  887. Occupation,--职业名称
  888. APPNTHOMEADDRESS
  889. from occupation_tmp b
  890. where b.scustid = a.scustid
  891. ) WHERE 1=1 ;
  892. EXCEPTION
  893. WHEN HIVE_EXCEPTION THEN
  894. log_exception('up_health_insurance_listing_1',sqlerrm(),sqlcode())
  895. WHEN Others THEN
  896. log_exception('up_health_insurance_listing_1',sqlerrm(),sqlcode())
  897. END;
  898. =======================================================================================================================================
  899. ===================================================用户关系信息解析插入====================================================================
  900. =======================================================================================================================================
  901. --更新individual 的用户关系
  902. CREATE OR REPLACE PROCEDURE up_individual_relationship() -- 创建存储过程
  903. IS
  904. BEGIN
  905. --清楚临时表数据
  906. EXCEPTION
  907. WHEN HIVE_EXCEPTION THEN
  908. log_exception('up_individual_relationship',sqlerrm(),sqlcode())
  909. WHEN Others THEN
  910. log_exception('up_individual_relationship',sqlerrm(),sqlcode())
  911. END;
  912. =======================================================================================================================================
  913. ===================================================用户上游客户ID去重临时表====================================================================
  914. =======================================================================================================================================
  915. DROP TABLE IF EXISTS scustid_unique_tmp;
  916. CREATE TABLE scustid_unique_tmp(
  917. scustid string COMMENT '上游客户号' ,
  918. indid string COMMENT '客户号'
  919. )
  920. COMMENT '用户上游客户ID去重临时表'
  921. STORED AS ES
  922. with shard number 10
  923. replication 1;
  924. --更新individual 的用户关系
  925. CREATE OR REPLACE PROCEDURE up_scustid_unique_tmp() -- 创建存储过程
  926. IS
  927. BEGIN
  928. --清楚临时表数据
  929. delete from scustid_unique_tmp;
  930. --插入临时表数据
  931. insert into scustid_unique_tmp(scustid,indid)
  932. select scustid,min(indid) from individual_search1 group by scustid;
  933. EXCEPTION
  934. WHEN HIVE_EXCEPTION THEN
  935. log_exception('up_scustid_unique_tmp',sqlerrm(),sqlcode())
  936. WHEN Others THEN
  937. log_exception('up_scustid_unique_tmp',sqlerrm(),sqlcode())
  938. END;
  939. =====================================================================================================================
  940. 1,105,462 ---581292 插入投保
  941. 1,105,500 ---578591 插入被保人
  942. 1,119,154 ---156901 插入UNION
  943. 1,119,154 ---row_number()over(), 使用row_number()over() 329312
  944. row_number()over() 行号