从SQL中的另一个xmlsequance中提取xmlsequence

时间:2014-10-03 02:33:01

标签: sql oracle plsql

xmlsequence的问题很小。我正在编写PL-SQL(Oracle)

让我们说,我的XML看起来像这样:

<Row name="Row1">
<Field name="Filed1">
    <Value1>
    </Value1>
</Field>
<Row name="Row2inRow1">
    <Field name="Filed2">
        <Value1>
        </Value1>
    </Field>
</Row>
<Row name="Row2inRow1">
    <Field name="Filed2">
        <Value1>
        </Value1>
    </Field>
</Row>

<Row name="Row1">
<Field name="Filed1">
    <Value1>
    </Value1>
</Field>
<Row name="Row2inRow1">
    <Field name="Filed2">
        <Value1>
        </Value1>
    </Field>
</Row>
<Row name="Row2inRow1">
    <Field name="Filed2">
        <Value1>
        </Value1>
    </Field>
</Row>

它有2倍相同&#34; Row1&#34;这是多重的,Row1中的内容更多,我有多重&#34; Row2inRow1&#34;。

问题是,我想从Ro2InRow1和Row1中选择值来连接它们,效果应该是:

Value1(来自1st Row1)|| Value1(来自1st Row2inRow1)

Value1(来自1st Row1)|| Value1(来自2nd Row2InRow1)

Value1(来自2nd Row1)|| Value1(来自3rd Row2inRow1)

Value1(来自2nd Row1)|| Value1(来自4th Row2InRow1)

我尝试以某种方式编写代码,但我无法强制我的查询正常工作:

declare
xml_data xmldata;
begin
for rec1 in(select extractvalue(value(x),'//Field[@name="Filed1"]/Value1') ValueOfField1,
from table(xmlsequence(extract(xml_data.data,'//Row[@name="Row1"]')))x )
loop
        dbms_output.put_line('1 : '|| ValueOfField1);
        for rec2 in(select extractvalue(value(x),'//Field[@name="Filed2"]/Value1') ValueOfField2,
        from table(xmlsequence(extract(xml_data.data,'//Row[@name="Row2inRow1"]')))k ) --? What here!
    loop
            dbms_output.put_line('1 : '|| ValueOfField2);
    end loop;

end loop;
end;

有什么想法吗? :(

0 个答案:

没有答案