geo*_*rge 2 regex xml oracle oracle11g
我在表中有一列包含xml类型的数据,但是采用varchar格式.一个示例原始数据是:
<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>
Run Code Online (Sandbox Code Playgroud)
我想知道我必须使用什么正则表达式来检索例如'BEVA30D' <old_template_code>?
我试过了
REGEXP_SUBSTR(table.column,
'<old_template_code>*</old_template_code>') "REGEXPR_SUBSTR"
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
忘记正则表达式.使用原生XMLType功能......
select extractValue(xmlparse(content T.column), '/old_template_code')
from table T;
Run Code Online (Sandbox Code Playgroud)
在基于示例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$;
Run Code Online (Sandbox Code Playgroud)
给了我价值
BEVA30D
Run Code Online (Sandbox Code Playgroud)
请享用.
PS:此外,忘记stackoverflow.com,使用Oracle文档.:-)