sql >> Database >  >> RDS >> Oracle

Oracle-extract van xml-afkapwaarde

Voer je dit uit in sqlplus? Extract retourneert een XMLType-instantie en wordt weergegeven volgens lang variabele, die standaard is ingesteld op 80. Als u de waarde verhoogt, kunt u de volledige URL zien.

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

Na het verhogen van de waarde voor de lange variabele,

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

U kunt de functie getStringVal gebruiken om het XMLType naar varchar2 te converteren, wat niet afhankelijk is van een lange variabele.

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



  1. Kan de MySQL-datum/tijd-waarde niet converteren naar System.DateTime.Kon de waarde 0/0/0000 0:00:00 niet opslaan?

  2. Macports mysql5 instellen onder Snow Leopard

  3. COALESCE() Functie in Oracle

  4. Naam SQL-queryparameter moet worden gedefinieerd