数据库clob字段数据解析

问题描述:业务数据复杂不固定,使用json格式存储在clob大字段中,后期需要通过sql批量取数据,怎么解决?

解决方法: 使用substr、 instr、 tochar、 casethen方法去实

方法描述:

substr 方法:substr(字符串,截取开始位置,截取长度) //返回截取的字

instr方法:instr( string1, string2 [, start_position [, nth_appearance ] ] )   /   instr(源字符串, 目标字符串, 起始位置, 匹配序号)

                解析:string2 的值要在string1中查找,是从start_position给出的数值(即:位置)开始在string1检索,检索第nth_appearance(几)次出现string2

tochar方法:最大支持4000字节

case 用法:case when <条件表达式> then 满足条件返回值 else 不满足条件返回值

 
     
 select j.custom_num as 客户号,
              j.trade_serinum,
              
              to_char(substr(m.workitem_message,
                             instr(m.workitem_message,
                                   '"shareholderIdNumber"',
                                   1,
                                   2) + 23,
                             (instr(m.workitem_message,
                                    '","shareholderIdNumber2"',
                                    1,
                                    2) - instr(m.workitem_message,
                                                '"shareholderIdNumber":',
                                                1,
                                                2) - 23))) as 控股股东1证件号码,
              (case
                when instr(m.workitem_message, '"shareholderAddress"', 1, 2) = '0' then
                 ''
                else
                 to_char(substr(m.workitem_message,
                                instr(m.workitem_message,
                                      '"shareholderAddress"',
                                      1,
                                      2) + 22,
                                (instr(m.workitem_message,
                                       '","shareholderAddress2"',
                                       1,
                                       2) - instr(m.workitem_message,
                                                   '"shareholderAddress":',
                                                   1,
                                                   2) - 22)))
              END) as 控股股东1住所,              
              (select max(s.TASK_SUBMIT_TIME)
                 from tbas_task_submit_message s
                where s.trade_serinum = j.trade_serinum
                  and s.task_code = 'A0314') as 任务提交时间
       
         from tbas_task_submit_message m, tbas_tradesernum_journal j
        where m.trade_serinum = j.trade_serinum
          and m.task_code = 'A0313'
          and j.TRADE_STATUS = 545
          and j.trade_start_time >
              to_date('20170530 00:00:00', 'yyyyMMdd HH24:mi:ss')
          and j.trade_start_time <=
              to_date('20170630 00:00:00', 'yyyyMMdd HH24:mi:ss');
         
   







你可能感兴趣的:(问题总结)