Oracle
 sql >> Database >  >> RDS >> Oracle

Estratto Oracle dal valore di troncamento xml

Lo stai eseguendo in sqlplus? Extract restituisce un'istanza XMLType e viene visualizzata in base a lungo variabile, il cui valore predefinito è 80. Se aumenti il ​​valore puoi vedere l'URL completo.

SQL> with x(contact_data) as (
select '<?xml version="1.0" encoding="UTF-8"?>
<service_orders count="1">
   <service_order order_number="fakefakefake" id="fakefakefake">
      <images count="2">
       <image src="https://s3.amazonaws.com/some_subfolder/deeper/deeper_still/ever_deeper/really_big_long_url_goes_here"/>
        </images>
</service_order>
</service_orders>' from dual
)
select
    length(extract(xmltype(contact_data),'/service_orders/service_order/images/image/@src')) as url_length,
    extract(xmltype(contact_data),'/service_orders/service_order/images/image/@src') as url
from
    x;  

URL_LENGTH
----------
URL
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       101
https://s3.amazonaws.com/some_subfolder/deeper/deeper_still/ever_deeper/really_b

Dopo aver aumentato il valore per la variabile lunga,

SQL> set long 120

SQL> with x(contact_data) as (
select '<?xml version="1.0" encoding="UTF-8"?>
<service_orders count="1">
   <service_order order_number="fakefakefake" id="fakefakefake">
      <images count="2">
       <image src="https://s3.amazonaws.com/some_subfolder/deeper/deeper_still/ever_deeper/really_big_long_url_goes_here"/>
        </images>
</service_order>
</service_orders>' from dual
)
select
    length(extract(xmltype(contact_data),'/service_orders/service_order/images/image/@src')) as url_length,
    extract(xmltype(contact_data),'/service_orders/service_order/images/image/@src') as url
from
    x;  

URL_LENGTH
----------
URL
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       101
https://s3.amazonaws.com/some_subfolder/deeper/deeper_still/ever_deeper/really_big_long_url_goes_here

Puoi utilizzare la funzione getStringVal per convertire XMLType in varchar2, che non dipende dalla variabile lunga.

SQL> set long 80

SQL> with x(contact_data) as (
select '<?xml version="1.0" encoding="UTF-8"?>
<service_orders count="1">
   <service_order order_number="fakefakefake" id="fakefakefake">
      <images count="2">
       <image src="https://s3.amazonaws.com/some_subfolder/deeper/deeper_still/ever_deeper/really_big_long_url_goes_here"/>
        </images>
</service_order>
</service_orders>' from dual
)
select
    length(extract(xmltype(contact_data),'/service_orders/service_order/images/image/@src')) as url_length,
    extract(xmltype(contact_data),'/service_orders/service_order/images/image/@src').getStringval() as url
from
    x; 

URL_LENGTH
----------
URL
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       101
https://s3.amazonaws.com/some_subfolder/deeper/deeper_still/ever_deeper/really_big_long_url_goes_here