[英]Regex expression oracle sql 11g to parse XML
I've got a column in a table which contains xml type of data but is in a varchar format. 我在表中有一列包含xml类型的数据,但是采用varchar格式。 An example raw of data is:
一个示例原始数据是:
<old_template_code>BEVA30D</old_template_code><old_template_name>Beva
30D France calls capped
15p</old_template_name><new_template_code>BEVA24M</new_template_code><new_template_name>Beva 24M France Calls Capped 15p</new_template_name>
I wonder what regex expression do I have to use to retrieve for example 'BEVA30D' from <old_template_code>
? 我想知道我必须使用什么正则表达式从
<old_template_code>
检索“BEVA30D”?
I've tried 我试过了
REGEXP_SUBSTR(table.column,
'<old_template_code>*</old_template_code>') "REGEXPR_SUBSTR"
but it doesn't work. 但它不起作用。
Forget about regexp. 忘记正则表达式。 Use the native XMLType functionality ...
使用原生XMLType功能......
select extractValue(xmlparse(content T.column), '/old_template_code')
from table T;
In an example based on your sample XML data: 在基于示例XML数据的示例中:
with source$ as (
select q'{
<old_template_code>BEVA30D</old_template_code><old_template_name>Beva
30D France calls capped
15p</old_template_name><new_template_code>BEVA24M</new_template_code><new_template_name>Beva 24M France Calls Capped 15p</new_template_name>
}' as source_xml
from dual
)
select extractValue(xmlparse(content source_xml), '/old_template_code')
from source$;
gives me the value of 给了我价值
BEVA30D
Enjoy. 请享用。
PS: Moreover, forget about stackoverflow.com, use Oracle documentation . PS:此外,忘记stackoverflow.com,使用Oracle文档 。 :-)
:-)
XML
approach is definitely the better one always. XML
方法绝对是更好的方法。
Still, A regular expression approach. 仍然是一种正则表达方法。
select regexp_replace(regexp_substr(table.column,'<old_template_code>.*</old_template_code>'),
'(<old_template_code>)(.*)(</old_template_code>)',
'\2')
from table;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.