Oracle extractvalue在另一个表中连接标签名的值



我有一个奇怪的场景,我有两个表与以下类型的数据,

table1: 
key1, xmldata1

    1,<start><dat1>hi/dat1><dat2>hello</dat2>........</end>
    2,<start><dat1>hihi/dat1><dat2>hellohello</dat2>.......</end>
table2:
key1, fld1, name1
    1, dat1, message1
    2, dat1, message2
    2, dat2, message3

我需要生成一个输出,以便使用key1连接表,并且对于table2中的列fld1,我应该连接与table1中的xmldata1标记名匹配的值。例如:-输出应该是

1, message1=hi
2, message2=hihi
2, message3=hellohello

这可能吗?表1中的Dat1, dat2, dat3标签xmldata1是动态的,可以有'n'个数据标签

是的,有可能…

select T2.key1, T2.name1, xmlcast(T1.xmldata1.extract('/start/'||T2.fld1) as varchar2(4000)) as message
from table2 T2
    join table1 T1
        on T1.key1 = T2.key1
;

select T2.key1, T2.name1, extractvalue(T1.xmldata1, '/start/'||T2.fld1) as message
from table2 T2
    join table1 T1
        on T1.key1 = T2.key1
;

最新更新