sql - How to pass value in xmltable -


how can pass variable value inside xpath of xmltable?

declare   v number := 0; begin   select *   xml_billrun_files t ,     xmltable('/invoice/ar_items[@elem='||v||']/items/usage_records/session_info'                passing t.update_xmldoc                columns chrg_duration varchar2(20) path 'duration',                        amount number path 'amount') x; end; 

i've tried one.

declare   v number := 0; begin   select *   xml_billrun_files t ,     xmltable('/invoice/ar_items[@elem=$i]/items/usage_records/session_info'                passing t.update_xmldoc, xmltype(v) "i"               columns chrg_duration varchar2(20) path 'duration',                        amount number path 'amount') x; end; 

but returns error:

ora-31011: xml parsing failed ora-19202: error occurred in xml processing lpx-00210: expected '<' instead of '0' error @ line 1 ora-06512: @ "sys.xmltype", line 310 ora-06512: @ line 1 ora-06512: @ line 5 31011. 00000 -  "xml parsing failed" *cause:    xml parser returned error while trying parse document. *action:   check if document parsed valid. 

thanks help.

in my answer previous question, incorrectly used xmltype(lp) "lp" xmlquery call. not sure why didn't complain there, didn't restrict match anyway...

for xmltable call can pass number directly, without conversion/cast, it's number:

  select chrg_duration, amount   ...   xml_billrun_files t ,     xmltable('/invoice/ar_items[@elem=$i]/items/usage_records/session_info'                passing t.update_xmldoc, v "i"               columns chrg_duration varchar2(20) path 'duration',                        amount number path 'amount') x; 

if you're doing in loop, index wrong data type, , need cast number:

  select chrg_duration, amount   ...   xml_billrun_files t ,     xmltable('/invoice/ar_items[@elem=$i]/items/usage_records/session_info'                passing t.update_xmldoc, cast(v number) "i"               columns chrg_duration varchar2(20) path 'duration',                        amount number path 'amount') x; 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -