regex - Oracle SQL regexp sum within repeating sequence grouped by -


first time here, hope can help

what's oracle sql select stmt xml below stored in oracle clob field following returned (there many 96 intvcoll blocks per day).

basically numeric values in intvcoll blocks between 2nd , 3rd commas need summed , grouped date before first comma , varchar after 3rd comma.

i'm guessing regexp_substr / can't quite there. first record sum of 1st , 2nd intvcoll blocks second record sum of 3rd intvcoll block third record sum of 4th , 5th

meterchannelid           date         sum     quality   count_of_records 6103044759-40011200-q1   14/03/2016   1,387           2    6103044759-40011200-q1   14/03/2016     694   s         1  6103044759-40011200-q1   15/03/2016   1,433           2    <uploadregdata>     <intervaldatablock>         <setdatetime>16/03/2016-19:30:01</setdatetime>         <intervalminute>15</intervalminute>         <meterchannelid>6103044759-40011200-q1</meterchannelid>         <intvcoll><intvdata>14/03/2016,1,700,a</intvdata></intvcoll>         <intvcoll><intvdata>14/03/2016,2,687,a</intvdata></intvcoll>         <intvcoll><intvdata>14/03/2016,3,694,s</intvdata></intvcoll>         <intvcoll><intvdata>15/03/2016,4,724,a</intvdata></intvcoll>         <intvcoll><intvdata>15/03/2016,5,709,a</intvdata></intvcoll>     </intervaldatablock> </uploadregdata> 

select meterchannelid,        "date",        sum( value ) "sum",        quality,        count(1) count_of_records   (   select meterchannelid,          to_date( substr( data, 1, 10 ), 'dd/mm/yyyy' ) "date",          to_number( substr(                       data,                       instr( data, ',', 1, 2 ),                       length( data ) - instr( data, ',', 1, 2 ) - 2                   ) ) value,          substr( data, -1 ) quality     (     select extractvalue( xml, '/uploadregdata/intervaldatablock/meterchannelid' )              meterchannelid,            extractvalue( d.column_value, '/intvdata' ) data       ( select xmltype( column_name ) xml table_name ) x,            table(              xmlsequence(                extract(                  x.xml,                  '/uploadregdata/intervaldatablock/intvcol1/intvdata'                )              )            ) d   ) ) group meterchannelid, "date", quality order meterchannelid, "date", quality; 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -