Oracle 10g : XML에서 데이터 추출(select)(CLOB Type)
저는 오라클을 처음 접했는데 선택에 사소한 문제가 있습니다(오라클 10g Express Edition을 사용하고 있습니다).
CLOB: mytab.xml 필드가 있는 DB 이 열에는 다음과 같은 XML이 있습니다.
<?xml version="1.0" encoding="iso-8859-1"?>
<info>
<id> 954 </id>
<idboss> 954 </idboss>
<name> Fausto </name>
<sorname> Anonimo </sorname>
<phone> 040000000 </phone>
<fax> 040000001 </fax>
</info>
예를 들어 '팩스' 태그 값을 얻기 위해 '간단한' 선택을 하려고 합니다.하지만 제가 약간의 문제가 있어서 제 실수를 이해할 수가 없습니다.예를 들어,
select extract(xml, '//fax').getStringVal() from mytab;
ORA-00932: inconsistent datatypes: expected - got
select extract(xmltype(xml), '//fax').getStringVal() from mytab;
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "SYS.XMLTYPE", line 254
저도 '추출가치'로 해봤는데 똑같은 문제가 있어요.어디서 내가 잘못한 겁니까?
대신 이 방법을 사용해 보십시오.
select xmltype(t.xml).extract('//fax/text()').getStringVal() from mytab t
사용해보기xmltype.createxml(xml)
.
와 마찬가지로.
select extract(xmltype.createxml(xml), '//fax').getStringVal() from mytab;
그것은 나에게 효과가 있었다.
더욱 개선하거나 조작하고 싶다면 말입니다.
이런 거 해보세요.
Select *
from xmltable(xmlnamespaces('some-name-space' as "ns",
'another-name-space' as "ns1",
),
'/ns/ns1/foo/bar'
passing xmltype.createxml(xml)
columns id varchar2(10) path '//ns//ns1/id',
idboss varchar2(500) path '//ns0//ns1/idboss',
etc....
) nice_xml_table
누군가에게 도움이 되길 바랍니다.
이 쿼리는 내 경우에 완벽하게 실행됩니다.
select xmltype(t.axi_content).extract('//Lexis-NexisFlag/text()').getStringVal() from ax_bib_entity t
아래의 쿼리로 달성할 수 있습니다.
select extract(xmltype(xml), '//fax/text()').getStringVal() from mytab;
select extractvalue(xmltype(xml), '//fax') from mytab;
CLOB XML에서 DBMS_XMLPARSER.parser 개체를 만들어 보고 DBMS_XMLDOM을 가져올 수 있습니다.DOM 문서 개체입니다.그런 다음 DBMS_XMLDOM 패키지 메서드를 사용하여 노드 값을 가져옵니다.
xml_ CLOB := 'X';
p DBMS_XMLPARSER.parser;
doc_ DBMS_XMLDOM.DOMDocument;
-- Convert the CLOB into a XML-document
P := DBMS_XMLPARSER.newparser();
-- Parse the clob and get the XML-document
DBMS_XMLPARSER.parseclob(p, xml_);
doc_ := DBMS_XMLPARSER.getDocument(p);
다음 방법을 사용하여 노드 값을 추출합니다.
DBMS_XMLDOM.getElementsByTagName(doc_, 'NodeName'); DBMS_XMLDOM.GetNodeValue(node_obj_);
DBMS_XMLDOM 메서드에 대한 자세한 내용은 여기를 참조하십시오.
다음의 경우:
<?xml version="1.0" encoding="iso-8859-1"?>
<info xmlns="http://namespaces.default" xmlns:ns2="http://namespaces.ns2" >
<id> 954 </id>
<idboss> 954 </idboss>
<name> Fausto </name>
<sorname> Anonimo </sorname>
<phone> 040000000 </phone>
<fax> 040000001 </fax>
</info>
쿼리:
Select *
from xmltable(xmlnamespaces(default 'http://namespaces.default'
'http://namespaces.ns2' as "ns",
),
'/info'
passing xmltype.createxml(xml)
columns id varchar2(10) path '/id',
idboss varchar2(500) path '/idboss',
etc....
) nice_xml_table
XML 저장소가 데이터베이스 테이블의 CLOB 필드에 있는 경우.예: 이 XML의 경우:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Awmds>
<General_segment>
<General_segment_id>
<Customs_office_code>000</Customs_office_code>
</General_segment_id>
</General_segment>
</Awmds>
다음은 추출 쿼리입니다.
SELECT EXTRACTVALUE (
xmltype (T.CLOB_COLUMN_NAME),
'/Awmds/General_segment/General_segment_id/Customs_office_code')
AS Customs_office_code
FROM TABLE_NAME t;
언급URL : https://stackoverflow.com/questions/4884421/oracle-10g-extract-data-select-from-xml-clob-type
'programing' 카테고리의 다른 글
PowerShell에서 실행 중인 프로세스 목록을 보는 방법 (0) | 2023.10.29 |
---|---|
안드로이드 전역 변수 (0) | 2023.10.29 |
wocommerce 웹 후크가 발사되지 않음 (0) | 2023.10.29 |
RestTemplate 스레드는 안전합니까? (0) | 2023.10.24 |
StackOverflow와 같은 "토스트" 메시지 생성 (0) | 2023.10.24 |