[英]Trying to use replace ((value),"\W","") on oracle xquery
Could someone explain why does replace \\w (word-character) work and \\W (non-word-character) does not .有人可以解释为什么替换 \\w (word-character) 工作而 \\W (non-word-character) 没有。 How to solve it.
如何解决。
create table test (xmldata) as
select xmltype('<workbook>
<worksheet sheetName="asd-kasd" sheetId="1"/>
</workbook>')
from dual;
update test
set XMLDATA=
xmlquery(
'copy $d := .
modify (
for $i in $d/workbook/worksheet/@sheetName
return replace value of node $i with concat("1.\w:",replace(string($i/../@sheetName),"\w",""),"2. \W:",replace($i/../@sheetName,"\W",""))
)
return $d'
passing test.XMLDATA
returning content
);
ORA-19112: error raised during evaluation:
XVM-01126: [FORX0003] Regular expression matches zero-length string
fiddle: https://dbfiddle.uk/?rdbms=oracle_18&fiddle=ede05cbbe55f36074c36457e9491fc11小提琴: https ://dbfiddle.uk/ ? rdbms = oracle_18 & fiddle =ede05cbbe55f36074c36457e9491fc11
Error:错误:
ORA-19112: error raised during evaluation:
XVM-01126: [FORX0003] Regular expression matches zero-length string
after using \\W使用后\\W
This seems to be a bug in Oracle's implementation of the standard XQuery fn:replace()
function.这似乎是 Oracle 标准 XQuery
fn:replace()
函数实现中的一个错误。 Using the metacharacter \\W
causes fn:replace
to fail, on every string that I tested.在我测试的每个字符串上,使用元字符
\\W
会导致fn:replace
失败。 I'd suggest opening a Service Request with Oracle Support to report it.我建议向 Oracle 支持部门提出服务请求以进行报告。
You can verify using an non-Oracle XQuery tester (eg here ) that replace()
should handle \\W
just fine.您可以使用非 Oracle XQuery 测试器(例如此处)验证
replace()
应该可以很好地处理\\W
。
Oddly, the deprecated ora:replace() function does work correctly.奇怪的是,已弃用的ora:replace()函数确实可以正常工作。 So you could use that as a workaround until Oracle patches the bug.
因此,在 Oracle 修补该错误之前,您可以将其用作解决方法。 But note that this function is non-standard - for example, it supports POSIX-style metacharacters (eg
[[:alnum:]]
) which the XQuery standard does not.但请注意,此函数是非标准的 - 例如,它支持 XQuery 标准不支持的 POSIX 样式的元字符(例如
[[:alnum:]]
)。
I simplified your query to give a more minimal verifiable example, and could reproduce the issue on Oracle 12.2.0.1.我简化了您的查询以提供一个更小的可验证示例,并且可以在 Oracle 12.2.0.1 上重现该问题。 Comment out the "fn" column to get correct results.
注释掉“fn”列以获得正确的结果。
select
regexp_replace('asd-kasd','\W','') as rr, -- normal regexp engine works fine
-- \W fails, with any string
xmlquery('fn:replace("asd-kasd","\W","")' returning content) as fn,
-- deprecated ora:replace works fine
xmlquery('ora:replace("asd-kasd","\W","")' returning content) as ora
from dual
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.