Reading TAGs from a XMLTYPE field
Francisco Moya, March 17, 2022 - 4:50 pm UTC
Hi Cris,
Thanks a Lot!!!
It worked as expected. The problem was the missing namespace in the select clause.
As I have no expertize working with XML, I didn´t know about the correct syntaxe.
I have more one doubt:
How I can get the content "CFe23220301438784004356592301302730184738086646" from the extract of the XML below, considering that the EXTRACVALUE command get data only for the nodes?
XML example (partial.....):
<CFe>
<infCFe Id="CFe23220301438784004356592301302730184738086646" versao="0.07" versaoDadosEnt="0.07" versaoSB="010006">
<ide>
<cUF>23</cUF>
<cNF>808664</cNF>
<mod>59</mod>
<nserieSAT>230130273</nserieSAT>
<nCFe>018473</nCFe>
<dEmi>20220303</dEmi>
<hEmi>115535</hEmi>
<cDV>6</cDV>
<tpAmb>1</tpAmb>
<CNPJ>54517628000198</CNPJ>
<signAC>LigakySvQZDIKXvaNBstALcMjKsGqKHr8o6HSmCogN3qj9+RqsaizEJbrftJPtqK1cW2+YzFgIEKPNUTOiYy4zbHFHk2CCU65XEwz4GjvLTpQJfPJCCrIHWPi7bBNFA1ADHGRBjV6IHVhW8YeHWxEvb18RmxUhnj4qtukNfl5NKON6xVfQ85toXfesvDRqJmkGIEuUI017DKSirkB/0v+itAKw+UJthgRWKmFEyBddKGrY3xPrjeziqqVD5DYIYGxZUDpCzdwG4T5Mm7hr9+2bClvHG8fg8Ss/IIaADLopfr3YzFwWkrvk61isAcqroYKkNodkZPmhwzYMhUTnAogg==</signAC>
<assinaturaQRCODE>VabAH61q4Oj7RBu8R0D0MzfPv8p0EuWwkrQ+ZN5kEO2p9iTwx/iqaUpEsOozJhtVTDVxiVSfSTDeDxfs66qMcyI6y/znFIzbdmDwMJhUg1pPdT8jT5e7XhgqlK6JOQTHJ8ZzneVN2JxPTynVFaSkH0ZjFjpMF7CVV2ykEPlbS/aYnSl5ovad2KcCMKC+KaQ1XlxmqOvHPK6XBJIAzn+E7kzByje57KdYOosOPbXThL7T+8rt2+EacPtHdK0H1DkWUYkCRQZzZ4NXgHtF5VEKmayWDxVFtqa2D4KGpDSilxRVj8rCFZ5v+lsZmdVFGanHl5dBwwK+Co+uhfUFcp8AsQ==</assinaturaQRCODE>
<numeroCaixa>030</numeroCaixa>
</ide>
.
.
.
Thanks in advance,
Francisco
March 18, 2022 - 5:00 am UTC
Something like this perhaps?
SQL> with testTable as
2 (
3 select xmltype('<CFe>
4 <infCFe Id="CFe23220301438784004356592301302730184738086646" versao="0.07" versaoDadosEnt="0.07" versaoSB="010006">
5 <ide>
6 <cUF>23</cUF>
7 <cNF>808664</cNF>
8 <mod>59</mod>
9 </ide>
10 </infCFe>
11 </CFe>') xml_val from dual
12 )
13 select xmlquery('/CFe/infCFe/@Id' passing xml_val returning content) as days
14 from testTable;
DAYS
------------------------------------------------------------------------------------------------------------------------
CFe23220301438784004356592301302730184738086646
Reading TAGs from a XMLTYPE field
Francisco Moya, March 18, 2022 - 5:45 pm UTC
When I run your command in PL-SQL, it runs well, but the content that I need is not shown In the column Days, appears <XMLTYPE> instead of CFe23220301438784004356592301302730184738086646.
I have to click in the button "..." , and there I have the required content in the column Text…
This content (CFe23220301438784004356592301302730184738086646) I have to use to update other tables/fields in the Oracle DB.
My doubts:
1.) How can I show the content “CFe23220301438784004356592301302730184738086646” and be able to use it later?
2.) When I run the same command, but using my table, it doesn't show anything, and keeps running as if in a Loop. I have to force the cancellation of PL-SQL.
SELECT xmlquery('/CFe/infCFe/@Id' passing conteudo returning content) as days
FROM dbcsi_p2k.tmp_teste_xml
WHERE ROWID = 'AABV2iABBAAILUdAAB';
The table dbcsi_p2k.tmp_teste_xml has the following layout:
CONTEUDO XMLTYPE
I´m Using:
PL-SQL: 11.0.3.1770
ORACLE: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Thank you !!!
March 21, 2022 - 4:32 am UTC
Can we have a complete test case please
- create table
- insert data
- then your SQL
Datatype returned by XMLQUERY
Kim Berg Hansen, March 22, 2022 - 2:59 pm UTC
Francisco,
The XMLQUERY function returns XMLTYPE datatype, so your "PL/SQL Developer" GUI tool shows this in the grid rather than the text.
Perhaps use XMLCAST on the output of XMLQUERY to make it return a VARCHAR2?
Cheerio
/Kim
March 23, 2022 - 2:28 am UTC
nice catch