您好,欢迎访问一九零五行业门户网

Oracle中通过游标执行带参数的存储过程实现解析CLOB字段内的xml

摘要:近来之前的项目数据出现了问题,原因是由于之前在设计数据库的时候把时间字段设置成了字符串式,所以给后期的数据操作带来了很大的麻烦,这里提醒一下各位程序猿,以后在开发项目的时候时间字段一定要是时间字段,不要为了方便操作就设成字符串,这样
摘要:近来之前的项目数据出现了问题,原因是由于之前在设计数据库的时候把时间字段设置成了字符串格式,所以给后期的数据操作带来了很大的麻烦,这里提醒一下各位程序猿,以后在开发项目的时候时间字段一定要是时间字段,不要为了方便操作就设成字符串,这样后期改你带来的麻烦是你想象不到的,接下来就看看我解决这个问题的方法吧!
一:存储数据的零时表:
二:零时表里clob字段里面存储的xml字符串格式:
三:存储解析完成的xml的数据表:
四:执行解析clob字段里面xml字符串的存储过程sql:
create or replace procedure mip.mip_parse (xmlstr in clob)is styp varchar2 (100); reno varchar2 (100); airline varchar2 (100); ffid varchar2 (100); ffid_a varchar2 (100); ffid_d varchar2 (100); abns varchar2 (100); acft varchar2 (100); chdt varchar2 (100); eibt varchar2 (100); fata varchar2 (100); feta varchar2 (100); fsta varchar2 (100); lmdt varchar2 (100); lmur varchar2 (100); pstm varchar2 (100); rway varchar2 (100); spot varchar2 (100); stnd varchar2 (100); sdec varchar2 (100); a_tobt varchar2 (100); a_weather varchar2 (100); asat varchar2 (100); bctm varchar2 (100); botm varchar2 (100); betm varchar2 (100); bstm varchar2 (100); c_tobt varchar2 (100); cobt varchar2 (100); ctot varchar2 (100); dint varchar2 (100); dlab varchar2 (100); dnap varchar2 (100); dout varchar2 (100); eddi varchar2 (100); eobt varchar2 (100); epgt varchar2 (100); epot varchar2 (100); fatd varchar2 (100); fstd varchar2 (100); oftm varchar2 (100); stdi varchar2 (100); tsat varchar2 (100); flightnumber varchar2 (100); flightmark varchar2 (100); alap varchar2 (100); aprt varchar2 (100); dprt varchar2 (100); park varchar2 (100); internalorinternational varchar2 (100); terminal varchar2 (100); grounddistribution varchar2 (100); --定义出港信息表要格式的时间字段 a_tobt_d varchar2 (100); asat_d varchar2 (100); bctm_d varchar2 (100); botm_d varchar2 (100); betm_d varchar2 (100); c_tobt_d varchar2 (100); cobt_d varchar2 (100); ctot_d varchar2 (100); dint_d varchar2 (100); dout_d varchar2 (100); eddi_d varchar2 (100); eobt_d varchar2 (100); epgt_d varchar2 (100); epot_d varchar2 (100); fatd_d varchar2 (100); fstd_d varchar2 (100); lmdt_d varchar2 (100); oftm_d varchar2 (100); stdi_d varchar2 (100); tsat_d varchar2 (100); --定义进港信息表要格式化的时间字段 bstm_a varchar2 (100); eibt_a varchar2 (100); fata_a varchar2 (100); feta_a varchar2 (100); fsta_a varchar2 (100); lmdt_a varchar2 (100); pstm_a varchar2 (100); spot_a varchar2 (100); counts number(36); --定义出港信息要修改的除时间外的字段 stnd_d varchar2 (100); a_weather_d varchar2 (100); abns_d varchar2 (100); acft_d varchar2 (100); airline_d varchar2 (100); dlab_d varchar2 (100); dnap_d varchar2 (100); lmur_d varchar2 (100); reno_d varchar2 (100); rway_d varchar2 (100); dprt_d varchar2 (100); park_d varchar2 (100); internalorinternational_d varchar2 (100); terminal_d varchar2 (100); grounddistribution_d varchar2 (100); --定义进港信息要修改的除时间外的字段 abns_a varchar2 (100); acft_a varchar2 (100); airline_a varchar2 (100); alap_a varchar2 (100); aprt_a varchar2 (100); chdt_a varchar2 (100); reno_a varchar2 (100); lmur_a varchar2 (100); rway_a varchar2 (100); stnd_a varchar2 (100); park_a varchar2 (100); internalorinternational_a varchar2 (100); terminal_a varchar2 (100); grounddistribution_a varchar2 (100); begin styp := getxmlnodevalue (xmlstr, 'styp'); reno := getxmlnodevalue (xmlstr, 'reno'); ffid := getxmlnodevalue (xmlstr, 'ffid'); abns := getxmlnodevalue (xmlstr, 'abns'); acft := getxmlnodevalue (xmlstr, 'acft'); chdt := getxmlnodevalue (xmlstr, 'chdt'); eibt := getxmlnodevalue (xmlstr, 'eibt'); fata := getxmlnodevalue (xmlstr, 'fata'); feta := getxmlnodevalue (xmlstr, 'feta'); fsta := getxmlnodevalue (xmlstr, 'fsta'); lmdt := getxmlnodevalue (xmlstr, 'lmdt'); lmur := getxmlnodevalue (xmlstr, 'lmur'); pstm := getxmlnodevalue (xmlstr, 'pstm'); rway := getxmlnodevalue (xmlstr, 'rway'); spot := getxmlnodevalue (xmlstr, 'spot'); stnd := getxmlnodevalue (xmlstr, 'stnd'); sdec := getxmlnodevalue (xmlstr, 'stnd'); a_tobt := getxmlnodevalue (xmlstr, 'a_tobt'); a_weather := getxmlnodevalue (xmlstr, 'a_weather'); alap := getxmlnodevalue (xmlstr, 'alap'); aprt := getxmlnodevalue (xmlstr, 'aprt'); asat := getxmlnodevalue (xmlstr, 'asat'); bctm := getxmlnodevalue (xmlstr, 'bctm'); botm := getxmlnodevalue (xmlstr, 'botm'); betm := getxmlnodevalue (xmlstr, 'betm'); bstm := getxmlnodevalue (xmlstr, 'bstm'); c_tobt := getxmlnodevalue (xmlstr, 'c_tobt'); cobt := getxmlnodevalue (xmlstr, 'cobt'); ctot := getxmlnodevalue (xmlstr, 'ctot'); dint := getxmlnodevalue (xmlstr, 'dint'); dlab := getxmlnodevalue (xmlstr, 'dlab'); dnap := getxmlnodevalue (xmlstr, 'dnap'); dout := getxmlnodevalue (xmlstr, 'dout'); eddi := getxmlnodevalue (xmlstr, 'eddi'); eobt := getxmlnodevalue (xmlstr, 'eobt'); epgt := getxmlnodevalue (xmlstr, 'epgt'); epot := getxmlnodevalue (xmlstr, 'epot'); fatd := getxmlnodevalue (xmlstr, 'fatd'); fstd := getxmlnodevalue (xmlstr, 'fstd'); oftm := getxmlnodevalue (xmlstr, 'oftm'); stdi := getxmlnodevalue (xmlstr, 'stdi'); tsat := getxmlnodevalue (xmlstr, 'tsat'); dprt := getxmlnodevalue (xmlstr, 'dprt'); park := getxmlnodevalue (xmlstr, 'park'); internalorinternational := getxmlnodevalue (xmlstr, 'internalorinternational'); terminal := getxmlnodevalue (xmlstr, 'terminal'); grounddistribution := getxmlnodevalue (xmlstr, 'grounddistribution'); --出港信息表中时间字段的时间格式函数的用法 a_tobt_d := formatdatevalue (a_tobt, 'a_tobt_d'); asat_d := formatdatevalue (asat, 'asat_d'); bctm_d := formatdatevalue (bctm, 'bctm_d'); botm_d := formatdatevalue (botm, 'botm_d'); betm_d := formatdatevalue (betm, 'betm_d'); c_tobt_d := formatdatevalue (c_tobt, 'c_tobt_d'); cobt_d := formatdatevalue (cobt, 'cobt_d'); ctot_d := formatdatevalue (ctot, 'ctot_d'); dint_d := formatdatevalue (dint, 'dint_d'); dout_d := formatdatevalue (dout, 'dout_d'); eddi_d := formatdatevalue (eddi, 'eddi_d'); eobt_d := formatdatevalue (eobt, 'eobt_d'); epgt_d := formatdatevalue (epgt, 'epgt_d'); epot_d := formatdatevalue (epot, 'epot_d'); fatd_d := formatdatevalue (fatd, 'fatd_d'); fstd_d := formatdatevalue (fstd, 'fstd_d'); lmdt_d := formatdatevalue (lmdt, 'lmdt_d'); oftm_d := formatdatevalue (oftm, 'oftm_d'); stdi_d := formatdatevalue (stdi, 'stdi_d'); tsat_d := formatdatevalue (tsat, 'tsat_d'); --进港信息表中时间字段的时间格式函数的用法 eibt_a := formatdatevalue (eibt, 'eibt_a'); fata_a := formatdatevalue (fata, 'fata_a'); feta_a := formatdatevalue (feta, 'feta_a'); fsta_a := formatdatevalue (fsta, 'fsta_a'); lmdt_a := formatdatevalue (lmdt, 'lmdt_a'); pstm_a := formatdatevalue (pstm, 'pstm_a'); spot_a := formatdatevalue (spot, 'spot_a'); bstm_a := formatdatevalue (bstm, 'bstm_a'); --出港信息要修改的除时间外的字段 stnd_d := getxmlnodevalue (xmlstr, 'stnd'); a_weather_d := getxmlnodevalue (xmlstr, 'a_weather'); abns_d := getxmlnodevalue (xmlstr, 'abns'); acft_d := getxmlnodevalue (xmlstr, 'acft'); airline_d := getxmlnodevalue (xmlstr, 'airline'); dlab_d := getxmlnodevalue (xmlstr, 'dlab'); dnap_d := getxmlnodevalue (xmlstr, 'dnap'); lmur_d := getxmlnodevalue (xmlstr, 'lmur'); reno_d := getxmlnodevalue (xmlstr, 'reno'); rway_d := getxmlnodevalue (xmlstr, 'rway'); dprt_d := getxmlnodevalue (xmlstr, 'dprt'); park_d := getxmlnodevalue (xmlstr, 'park'); terminal_d := getxmlnodevalue (xmlstr, 'terminal'); grounddistribution_d := getxmlnodevalue (xmlstr, 'grounddistribution'); --进港信息要修改的除时间外的字段 abns_a := getxmlnodevalue (xmlstr, 'abns'); acft_a := getxmlnodevalue (xmlstr, 'acft'); airline_a := getxmlnodevalue (xmlstr, 'airline'); alap_a := getxmlnodevalue (xmlstr, 'alap'); aprt_a := getxmlnodevalue (xmlstr, 'aprt'); chdt_a := getxmlnodevalue (xmlstr, 'chdt'); reno_a := getxmlnodevalue (xmlstr, 'reno'); lmur_a := getxmlnodevalue (xmlstr, 'lmur'); rway_a := getxmlnodevalue (xmlstr, 'rway'); stnd_a := getxmlnodevalue (xmlstr, 'stnd'); park_a := getxmlnodevalue (xmlstr, 'park'); terminal_a := getxmlnodevalue (xmlstr, 'terminal'); grounddistribution_a := getxmlnodevalue (xmlstr, 'grounddistribution'); if styp = 'fgis' then if instr(ffid,'-d-') > 0 then ffid_d := ffid; --截取航空公司代码 airline := substr(ffid_d,0,2); --截取航班号 flightnumber := substr(ffid_d,instr(ffid_d,'-',1)+1,instr(ffid_d,'-',instr(ffid_d,'-',1)+1)-instr(ffid_d,'-',1)-1); --截取出港标志 flightmark := substr(ffid_d,instr(ffid_d,'-',2,2)+1,instr(ffid_d,'-',2,3)-1-instr(ffid_d,'-',2,2)); --截取进离港标志 internalorinternational := substr(ffid_d,-1); --update之前要先根据ffid查询一下看看数据表中是否已经存在该条数据,如果存在就update,如果不存在就save select count(1) into counts from tb_cms_flgtinfo_d where ffid = ffid_d; if counts > 0 then if a_tobt_d != ' ' then update tb_cms_flgtinfo_d set a_tobt = a_tobt_d where ffid = ffid_d; end if; if a_weather_d != ' ' then update tb_cms_flgtinfo_d set a_weather = a_weather_d where ffid = ffid_d; end if; if abns_d != ' ' then update tb_cms_flgtinfo_d set abns = abns_d where ffid = ffid_d; end if; if acft_d != ' ' then update tb_cms_flgtinfo_d set acft = acft_d where ffid = ffid_d; end if; if asat_d != ' ' then update tb_cms_flgtinfo_d set asat = asat_d where ffid = ffid_d; end if; if bctm_d != ' ' then update tb_cms_flgtinfo_d set bctm = bctm_d where ffid = ffid_d; end if; if botm_d != ' ' then update tb_cms_flgtinfo_d set botm = botm_d where ffid = ffid_d; end if; if betm_d != ' ' then update tb_cms_flgtinfo_d set betm = betm_d where ffid = ffid_d; end if; if c_tobt_d != ' ' then update tb_cms_flgtinfo_d set c_tobt = c_tobt_d where ffid = ffid_d; end if; if cobt_d != ' ' then update tb_cms_flgtinfo_d set cobt = cobt_d where ffid = ffid_d; end if; if ctot_d != ' ' then update tb_cms_flgtinfo_d set ctot = ctot_d where ffid = ffid_d; end if; if dint_d != ' ' then update tb_cms_flgtinfo_d set dint = dint_d where ffid = ffid_d; end if; if dlab_d != ' ' then update tb_cms_flgtinfo_d set dlab = dlab_d where ffid = ffid_d; end if; if dnap_d != ' ' then update tb_cms_flgtinfo_d set dnap = dnap_d where ffid = ffid_d; end if; if dout_d != ' ' then update tb_cms_flgtinfo_d set dout = dout_d where ffid = ffid_d; end if; if eddi_d != ' ' then update tb_cms_flgtinfo_d set eddi = eddi_d where ffid = ffid_d; end if; if eobt_d != ' ' then update tb_cms_flgtinfo_d set eobt = eobt_d where ffid = ffid_d; end if; if epgt_d != ' ' then update tb_cms_flgtinfo_d set epgt = epgt_d where ffid = ffid_d; end if; if epot_d != ' ' then update tb_cms_flgtinfo_d set epot = epot_d where ffid = ffid_d; end if; if fatd_d != ' ' then update tb_cms_flgtinfo_d set fatd = fatd_d where ffid = ffid_d; end if; if fstd_d != ' ' then update tb_cms_flgtinfo_d set fstd = fstd_d where ffid = ffid_d; end if; if lmdt_d != ' ' then update tb_cms_flgtinfo_d set lmdt = lmdt_d where ffid = ffid_d; end if; if lmur_d != ' ' then update tb_cms_flgtinfo_d set lmur = lmur_d where ffid = ffid_d; end if; if oftm_d != ' ' then update tb_cms_flgtinfo_d set oftm = oftm_d where ffid = ffid_d; end if; if reno_d != ' ' then update tb_cms_flgtinfo_d set reno = reno_d where ffid = ffid_d; end if; if rway_d != ' ' then update tb_cms_flgtinfo_d set rway = rway_d where ffid = ffid_d; end if; if stdi_d != ' ' then update tb_cms_flgtinfo_d set stdi = stdi_d where ffid = ffid_d; end if; if stnd_d != ' ' then update tb_cms_flgtinfo_d set stnd = stnd_d where ffid = ffid_d; end if; if tsat_d != ' ' then update tb_cms_flgtinfo_d set tsat = tsat_d where ffid = ffid_d; end if; if dprt_d != ' ' then update tb_cms_flgtinfo_d set dprt = dprt_d where ffid = ffid_d; end if; if park_d != ' ' then update tb_cms_flgtinfo_d set park = park_d where ffid = ffid_d; end if; if terminal_d != ' ' then update tb_cms_flgtinfo_d set terminal = terminal_d where ffid = ffid_d; end if; if grounddistribution_d != ' ' then update tb_cms_flgtinfo_d set grounddistribution = grounddistribution_d where ffid = ffid_d; end if; else insert into tb_cms_flgtinfo_d (id,a_tobt,a_weather,abns,acft,airline,asat,bctm,botm,betm,c_tobt,cobt,ctot,dint,dlab,dnap,dout,dprt,eddi,eobt,epgt,epot,fatd,ffid,flightnumber, flightmark,fstd,grounddistribution,internalorinternational,lmdt,lmur,oftm,park,reno,rway,stdi,stnd,terminal,tsat) values (flgtinfo_d_seq.nextval, a_tobt_d, a_weather, abns, acft, airline, asat_d, bctm_d, botm_d, betm_d, c_tobt_d, cobt_d, ctot_d, dint_d, dlab, dnap, dout_d, dprt, eddi_d, eobt_d, epgt_d, epot_d, fatd_d, ffid_d, flightnumber, flightmark, fstd_d, grounddistribution, internalorinternational, lmdt_d, lmur, oftm_d, park, reno, rway, stdi_d, stnd, terminal, tsat_d); end if; else ffid_a := ffid; --截取航空公司代码 airline := substr(ffid_a,0,2); --截取航班号 flightnumber := substr(ffid_a,instr(ffid_a,'-',1)+1,instr(ffid_a,'-',instr(ffid_a,'-',1)+1)-instr(ffid_a,'-',1)-1); --截取出港标志 flightmark := substr(ffid_a,instr(ffid_a,'-',2,2)+1,instr(ffid_a,'-',2,3)-1-instr(ffid_a,'-',2,2)); --截取进离港标志 internalorinternational := substr(ffid_a,-1); --update之前要先根据ffid查询一下看看数据表中是否已经存在该条数据,如果存在就update,如果不存在就save select count(1) into counts from tb_cms_flgtinfo_a where ffid = ffid_a; if counts > 0 then if abns_a != ' ' then update tb_cms_flgtinfo_a set abns = abns_a where ffid = ffid_a; end if; if acft_a != ' ' then update tb_cms_flgtinfo_a set acft = acft_a where ffid = ffid_a; end if; if alap_a != ' ' then update tb_cms_flgtinfo_a set alap = alap_a where ffid = ffid_a; end if; if bstm_a != ' ' then update tb_cms_flgtinfo_a set bstm = bstm_a where ffid = ffid_a; end if; if chdt_a != ' ' then update tb_cms_flgtinfo_a set chdt = chdt_a where ffid = ffid_a; end if; if reno_a != ' ' then update tb_cms_flgtinfo_a set reno = reno_a where ffid = ffid_a; end if; if eibt_a != ' ' then update tb_cms_flgtinfo_a set eibt = eibt_a where ffid = ffid_a; end if; if fata_a != ' ' then update tb_cms_flgtinfo_a set fata = fata_a where ffid = ffid_a; end if; if feta_a != ' ' then update tb_cms_flgtinfo_a set feta = feta_a where ffid = ffid_a; end if; if fsta_a != ' ' then update tb_cms_flgtinfo_a set fsta = fsta_a where ffid = ffid_a; end if; if lmdt_a != ' ' then update tb_cms_flgtinfo_a set lmdt = lmdt_a where ffid = ffid_a; end if; if lmur_a != ' ' then update tb_cms_flgtinfo_a set lmur = lmur_a where ffid = ffid_a; end if; if pstm_a != ' ' then update tb_cms_flgtinfo_a set pstm = pstm_a where ffid = ffid_a; end if; if rway_a != ' ' then update tb_cms_flgtinfo_a set rway = rway_a where ffid = ffid_a; end if; if spot_a != ' ' then update tb_cms_flgtinfo_a set spot = spot_a where ffid = ffid_a; end if; if stnd_a != ' ' then update tb_cms_flgtinfo_a set stnd = stnd_a where ffid = ffid_a; end if; if aprt_a != ' ' then update tb_cms_flgtinfo_a set aprt = aprt_a where ffid = ffid_a; end if; if park_a != ' ' then update tb_cms_flgtinfo_a set park = park_a where ffid = ffid_a; end if; if terminal_a != ' ' then update tb_cms_flgtinfo_a set terminal = terminal_a where ffid = ffid_a; end if; if grounddistribution_a != ' ' then update tb_cms_flgtinfo_a set grounddistribution = grounddistribution_a where ffid = ffid_a; end if; else insert into tb_cms_flgtinfo_a (id,abns,acft,airline,alap,bstm,chdt,aprt,ffid,flightnumber,flightmark,grounddistribution,internalorinternational,reno,eibt,fata,feta,fsta,lmdt,lmur,park,pstm,rway,spot,stnd,terminal) values (flgtinfo_a_seq.nextval, abns, acft, airline, alap, bstm_a, chdt, aprt, ffid_a, flightnumber, flightmark, grounddistribution, internalorinternational, reno, eibt_a, fata_a, feta_a, fsta_a, lmdt_a, lmur, park, pstm_a, rway, spot_a, stnd, terminal); end if; end if; else if instr(ffid,'-d-') > 0 then ffid_d := ffid; --截取航空公司代码 airline := substr(ffid_d,0,2); --截取航班号 flightnumber := substr(ffid_d,instr(ffid_d,'-',1)+1,instr(ffid_d,'-',instr(ffid_d,'-',1)+1)-instr(ffid_d,'-',1)-1); --截取出港标志 flightmark := substr(ffid_d,instr(ffid_d,'-',2,2)+1,instr(ffid_d,'-',2,3)-1-instr(ffid_d,'-',2,2)); --截取进离港标志 internalorinternational := substr(ffid_d,-1); --update之前要先根据ffid查询一下看看数据表中是否已经存在该条数据,如果存在就update,如果不存在就save select count(1) into counts from tb_cms_flgtinfo_d where ffid = ffid_d; if counts > 0 then if a_tobt_d != ' ' then update tb_cms_flgtinfo_d set a_tobt = a_tobt_d where ffid = ffid_d; end if; if a_weather_d != ' ' then update tb_cms_flgtinfo_d set a_weather = a_weather_d where ffid = ffid_d; end if; if abns_d != ' ' then update tb_cms_flgtinfo_d set abns = abns_d where ffid = ffid_d; end if; if acft_d != ' ' then update tb_cms_flgtinfo_d set acft = acft_d where ffid = ffid_d; end if; if asat_d != ' ' then update tb_cms_flgtinfo_d set asat = asat_d where ffid = ffid_d; end if; if bctm_d != ' ' then update tb_cms_flgtinfo_d set bctm = bctm_d where ffid = ffid_d; end if; if botm_d != ' ' then update tb_cms_flgtinfo_d set botm = botm_d where ffid = ffid_d; end if; if betm_d != ' ' then update tb_cms_flgtinfo_d set betm = betm_d where ffid = ffid_d; end if; if c_tobt_d != ' ' then update tb_cms_flgtinfo_d set c_tobt = c_tobt_d where ffid = ffid_d; end if; if cobt_d != ' ' then update tb_cms_flgtinfo_d set cobt = cobt_d where ffid = ffid_d; end if; if ctot_d != ' ' then update tb_cms_flgtinfo_d set ctot = ctot_d where ffid = ffid_d; end if; if dint_d != ' ' then update tb_cms_flgtinfo_d set dint = dint_d where ffid = ffid_d; end if; if dlab_d != ' ' then update tb_cms_flgtinfo_d set dlab = dlab_d where ffid = ffid_d; end if; if dnap_d != ' ' then update tb_cms_flgtinfo_d set dnap = dnap_d where ffid = ffid_d; end if; if dout_d != ' ' then update tb_cms_flgtinfo_d set dout = dout_d where ffid = ffid_d; end if; if eddi_d != ' ' then update tb_cms_flgtinfo_d set eddi = eddi_d where ffid = ffid_d; end if; if eobt_d != ' ' then update tb_cms_flgtinfo_d set eobt = eobt_d where ffid = ffid_d; end if; if epgt_d != ' ' then update tb_cms_flgtinfo_d set epgt = epgt_d where ffid = ffid_d; end if; if epot_d != ' ' then update tb_cms_flgtinfo_d set epot = epot_d where ffid = ffid_d; end if; if fatd_d != ' ' then update tb_cms_flgtinfo_d set fatd = fatd_d where ffid = ffid_d; end if; if fstd_d != ' ' then update tb_cms_flgtinfo_d set fstd = fstd_d where ffid = ffid_d; end if; if lmdt_d != ' ' then update tb_cms_flgtinfo_d set lmdt = lmdt_d where ffid = ffid_d; end if; if lmur_d != ' ' then update tb_cms_flgtinfo_d set lmur = lmur_d where ffid = ffid_d; end if; if oftm_d != ' ' then update tb_cms_flgtinfo_d set oftm = oftm_d where ffid = ffid_d; end if; if reno_d != ' ' then update tb_cms_flgtinfo_d set reno = reno_d where ffid = ffid_d; end if; if rway_d != ' ' then update tb_cms_flgtinfo_d set rway = rway_d where ffid = ffid_d; end if; if stdi_d != ' ' then update tb_cms_flgtinfo_d set stdi = stdi_d where ffid = ffid_d; end if; if sdec != ' ' then update tb_cms_flgtinfo_d set sdec = sdec where ffid = ffid_d; end if; if tsat_d != ' ' then update tb_cms_flgtinfo_d set tsat = tsat_d where ffid = ffid_d; end if; if dprt_d != ' ' then update tb_cms_flgtinfo_d set dprt = dprt_d where ffid = ffid_d; end if; if park_d != ' ' then update tb_cms_flgtinfo_d set park = park_d where ffid = ffid_d; end if; if terminal_d != ' ' then update tb_cms_flgtinfo_d set terminal = terminal_d where ffid = ffid_d; end if; if grounddistribution_d != ' ' then update tb_cms_flgtinfo_d set grounddistribution = grounddistribution_d where ffid = ffid_d; end if; else insert into tb_cms_flgtinfo_d (id,a_tobt,a_weather,abns,acft,airline,asat,bctm,botm,betm,c_tobt,cobt,ctot,dint,dlab,dnap,dout,dprt,eddi,eobt,epgt,epot,fatd,ffid,flightnumber, flightmark,fstd,grounddistribution,internalorinternational,lmdt,lmur,oftm,park,reno,rway,stdi,sdec,terminal,tsat) values (flgtinfo_d_seq.nextval, a_tobt_d, a_weather, abns, acft, airline, asat_d, bctm_d, botm_d, betm_d, c_tobt_d, cobt_d, ctot_d, dint_d, dlab, dnap, dout_d, dprt, eddi_d, eobt_d, epgt_d, epot_d, fatd_d, ffid_d, flightnumber, flightmark, fstd_d, grounddistribution, internalorinternational, lmdt_d, lmur, oftm_d, park, reno, rway, stdi_d, sdec, terminal, tsat_d); end if; else ffid_a := ffid; --截取航空公司代码 airline := substr(ffid_a,0,2); --截取航班号 flightnumber := substr(ffid_a,instr(ffid_a,'-',1)+1,instr(ffid_a,'-',instr(ffid_a,'-',1)+1)-instr(ffid_a,'-',1)-1); --截取出港标志 flightmark := substr(ffid_a,instr(ffid_a,'-',2,2)+1,instr(ffid_a,'-',2,3)-1-instr(ffid_a,'-',2,2)); --截取进离港标志 internalorinternational := substr(ffid_a,-1); --update之前要先根据ffid查询一下看看数据表中是否已经存在该条数据,如果存在就update,如果不存在就save select count(1) into counts from tb_cms_flgtinfo_a where ffid = ffid_a; if counts > 0 then if abns_a != ' ' then update tb_cms_flgtinfo_a set abns = abns_a where ffid = ffid_a; end if; if acft_a != ' ' then update tb_cms_flgtinfo_a set acft = acft_a where ffid = ffid_a; end if; if alap_a != ' ' then update tb_cms_flgtinfo_a set alap = alap_a where ffid = ffid_a; end if; if bstm_a != ' ' then update tb_cms_flgtinfo_a set bstm = bstm_a where ffid = ffid_a; end if; if chdt_a != ' ' then update tb_cms_flgtinfo_a set chdt = chdt_a where ffid = ffid_a; end if; if reno_a != ' ' then update tb_cms_flgtinfo_a set reno = reno_a where ffid = ffid_a; end if; if eibt_a != ' ' then update tb_cms_flgtinfo_a set eibt = eibt_a where ffid = ffid_a; end if; if fata_a != ' ' then update tb_cms_flgtinfo_a set fata = fata_a where ffid = ffid_a; end if; if feta_a != ' ' then update tb_cms_flgtinfo_a set feta = feta_a where ffid = ffid_a; end if; if fsta_a != ' ' then update tb_cms_flgtinfo_a set fsta = fsta_a where ffid = ffid_a; end if; if lmdt_a != ' ' then update tb_cms_flgtinfo_a set lmdt = lmdt_a where ffid = ffid_a; end if; if lmur_a != ' ' then update tb_cms_flgtinfo_a set lmur = lmur_a where ffid = ffid_a; end if; if pstm_a != ' ' then update tb_cms_flgtinfo_a set pstm = pstm_a where ffid = ffid_a; end if; if rway_a != ' ' then update tb_cms_flgtinfo_a set rway = rway_a where ffid = ffid_a; end if; if spot_a != ' ' then update tb_cms_flgtinfo_a set spot = spot_a where ffid = ffid_a; end if; if stnd_a != ' ' then update tb_cms_flgtinfo_a set stnd = stnd_a where ffid = ffid_a; end if; if aprt_a != ' ' then update tb_cms_flgtinfo_a set aprt = aprt_a where ffid = ffid_a; end if; if park_a != ' ' then update tb_cms_flgtinfo_a set park = park_a where ffid = ffid_a; end if; if terminal_a != ' ' then update tb_cms_flgtinfo_a set terminal = terminal_a where ffid = ffid_a; end if; if grounddistribution_a != ' ' then update tb_cms_flgtinfo_a set grounddistribution = grounddistribution_a where ffid = ffid_a; end if; else insert into tb_cms_flgtinfo_a (id,abns,acft,airline,alap,bstm,chdt,aprt,ffid,flightnumber,flightmark,grounddistribution,internalorinternational,reno,eibt,fata,feta,fsta,lmdt,lmur,park,pstm,rway,spot,stnd,terminal) values (flgtinfo_a_seq.nextval, abns, acft, airline, alap, bstm_a, chdt, aprt, ffid_a, flightnumber, flightmark, grounddistribution, internalorinternational, reno, eibt_a, fata_a, feta_a, fsta_a, lmdt_a, lmur, park, pstm_a, rway, spot_a, stnd, terminal); end if; end if; end if; commit;exception when others then dbms_output.put_line (sqlerrm);end mip_parse;/
五:存储过程里面用到的function.sql:
create or replace function mip.formatdatevalue (key varchar2, value varchar2) return varchar2is --定义几个变量,出来解析过来的时间字符串 --日月年时分(11oct141024) str varchar2(32); aa varchar2(32); day varchar2(32); mounth varchar2(32); year varchar2(32); hour varchar2(32); minute varchar2(32); valuereturn varchar2 (64);begin if key != ' ' then day := substr(key,0,2); mounth := substr(key,3,3); if instr (mounth,'jan') > 0 then mounth := 01; end if; if instr (mounth,'feb') > 0 then mounth := 02; end if; if instr (mounth,'mar') > 0 then mounth := 03; end if; if instr (mounth,'apr') > 0 then mounth := 04; end if; if instr (mounth,'may') > 0 then mounth := 05; end if; if instr (mounth,'jun') > 0 then mounth := 06; end if; if instr (mounth,'jul') > 0 then mounth := 07; end if; if instr (mounth,'aug') > 0 then mounth := 08; end if; if instr (mounth,'sep') > 0 then mounth := 09; end if; if instr (mounth,'oct') > 0 then mounth := 10; end if; if instr (mounth,'nov') > 0 then mounth := 11; end if; if instr (mounth,'dec') > 0 then mounth := 12; end if; year := substr(key,6,2); hour := substr(key,8,2); minute := substr(key,-2); aa := 20; str := 0; --日月年时分(11oct141017) if length(mounth)

六:最后是调用存储过程执行解析clob字段里面的xml字符串的游标sql:
/* formatted on 2015/1/15 14:20:27 (qp5 v5.115.810.9015) */declare --定义游标 cursor c_cursor is --这里查询指定时间内的数据,根据时间判断一下id>那个编号开始 select mbinmsgs_clob_msg from mbinmsgs_temp; v_mbinmsgs_clob_msg mbinmsgs_temp.mbinmsgs_clob_msg%type;begin --打开游标 open c_cursor; --提取游标数据 fetch c_cursor into v_mbinmsgs_clob_msg; while c_cursor%found loop dbms_output.put_line (v_mbinmsgs_clob_msg); fetch c_cursor into v_mbinmsgs_clob_msg; mip_parse(v_mbinmsgs_clob_msg); end loop;end;
总结:以上所以的sql操作都是在pl/sql中完成的,这样执行完成后的结果就是把零时表里面的所有的clob字段里面的xml解析并更新到对应的数据表中。
其它类似信息

推荐信息