1

我有 2 个需要在嵌套 FLWOR 语句中引用的 xml 文档。

MJH 源.xml

<data-set>
 <record>
 <table>CONTACT</table>
 <column>AGGREGATE_REPORT</column>
 <change>Dropped</change>
 <logic>Related to agCenter</logic>
 </record>
<record>
 <table>QNR_DESIGN_TEMPLATE</table>
 <column>LOGO1</column>
 <change>Dropped</change>
 <logic>Related to agCenter</logic>
</record>
</data-set>

这是外部文档,我需要提取每行的“表”和“列”值。

MVReport - 包含 SQL 语句的报告文档的集合。

....
<xml-property name="queryText"><![CDATA[select v.*
from poi_visit_details_v v
where v.site_id=? 
and v.std_code_id in ('15', 'TelephoneMonitoringVisit')
and to_char(v.actual_visit_date, 'yyyy-mm-dd') = substr(?, 0, 10)
and (reports_access_pk.site_access(v.SITE_ID, ?) = 'Y'
or reports_access_pk.superuser_access(?) = 'Y')
]]></xml-property>
<xml-property name="queryText"><![CDATA[select v.*
from poi_visit_details_v v
where v.site_id=? 
and v.std_code_id in ('15', 'TelephoneMonitoringVisit')
and to_char(v.actual_visit_date, 'yyyy-mm-dd') = substr(?, 0, 10)
and (reports_access_pk.site_access(v.SITE_ID, ?) = 'Y'
or reports_access_pk.superuser_access(?) = 'Y')
]]></xml-property>

……

这个集合是内部循环,我需要在其中查找包含单词“select”和从外部循环返回的“table”、“column”值的所有 SQL 语句。

这是我的xquery。

我遇到的问题是如何在内部循环的“where ... and ...”子句中引用外部“table”、“column”值?

for $target in doc("H:\MJH source.xml")/data-set/record
let $tTable := $target/table
let $tColumn := $target/column
for $sql in collection("MVReport") //*:xml-property[@name = "queryText"]
where $sql contains text "select"
and $sql contains $tTable
and $sql contains $tColumn
let $report := base-uri()
return <report><name>{$sql/base-uri()}</name><sql>{$sql}</sql></report>

谢谢你的帮助。

4

0 回答 0