누군가 Oracle의 XMLType 열에서 데이터를 검색하는 데 도움을 줄 수 있습니까?
drop table xml_analysis;
create table xml_analysis(id number,soft_attributes XMLType);
create table xml_softattributes(id number,soft_attributes varchar2(200));
INSERT INTO xml_analysis VALUES
( 1, XMLType(
'<softattributes>
<attr1>ABC</attr1>
<attr2>XYZ</attr2>
<attr3>PQR</attr3>
</softattributes>
'));
insert into xml_softattributes values(1,'attr1');
insert into xml_softattributes values(1,'attr2');
insert into xml_softattributes values(1,'attr3');
이제 내 문제는 xml_softattributes 테이블을 사용하여 xml_analysis 테이블에서 데이터를 동적으로 검색하는 것입니다. 어떻게 할 수 있습니까?
필요한 출력
Softattribute Value
=======================
attr1 ABC
attr2 XYZ
attr3 PQR
내가 생각할 수있는 가능한 해결책은 동적 문자열을 사용하고 실행하는 것이지만 동적 문자열 쿼리가 데이터를 검색하고 싶지는 않습니다.
다음과 같이 existsNode
와 extract
기능 의 조합을 사용할 수 있습니다 .
SELECT b.SOFT_ATTRIBUTES,
CASE
WHEN existsNode (a.soft_attributes ,'/*/'
||b.SOFT_ATTRIBUTES) = 1
THEN a.soft_attributes.extract('/*/'
||b.SOFT_ATTRIBUTES
||'/text()').getStringVal()
END value
FROM xml_analysis a,
xml_softattributes b
WHERE a.id = b.id;
*
하위 노드와 일치하는 와일드 카드로 사용됩니다. 예를 들어, / PO / * / STREET는 PO 요소의 손자 인 모든 거리 요소와 일치합니다.
산출:
attr1 ABC
attr2 XYZ
attr3 PQR
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다