简体   繁体   English

Oracle XML使用其他列中的值提取XPath

[英]Oracle XML Extract XPath using values from other columns

I have a CLOB that contains an XML that has information for each row in a detail table. 我有一个包含XML的CLOB,该XML具有明细表中每一行的信息。 I want to extract the node text from the XML that applies to just the current detail row. 我想从仅适用于当前详细信息行的XML中提取节点文本。 The XPath for the extract would say essentially [@Line_ID=X] where X is the current row's LINE_ID value. 提取的XPath基本上是[@Line_ID=X] ,其中X是当前行的LINE_ID值。 Currently, I can only see how to hard-code the XPath in the extract command. 当前,我只能看到如何在extract命令中对XPath进行硬编码。 The following SQL Fiddle shows the problem and the hard-coded XPath returning the wrong rows for the 2nd+ rows. 以下SQL Fiddle显示了该问题以及硬编码的XPath返回了第二个以上行的错误行。

SQL Fiddle showing incorrect Oracle results. SQL Fiddle 显示错误的Oracle结果。

I need this solution for both Oracle and SQL Server, and I was able to figure out the solution in SQL Server using the sql:column XPath function . 我对于Oracle和SQL Server都需要此解决方案,并且能够使用sql:column XPath 函数在SQL Server中找出解决方案。 This SQL Fiddle shows the correct results on a SQL Server database. 此SQL Fiddle 在SQL Server数据库上显示正确的结果

Is there an Oracle equivalent of the SQL Server sql:column function? 是否有与SQL Server sql:column函数等效的Oracle?

I was over-thinking this problem. 我想得太多了。 Oracle allows you to use string concatenation inside the XPath. Oracle允许您在XPath内部使用字符串连接。 The XPath ends up looking like [@Line_ID="' || DtlAlias.Line_ID || '"] XPath最终看起来像[@Line_ID="' || DtlAlias.Line_ID || '"]

An updated Fiddle that shows the correct results. 更新的小提琴显示正确的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM