Oracle
 sql >> Teknologi Basis Data >  >> RDS >> Oracle

Ekstrak Oracle dari nilai pemotongan xml

Apakah Anda menjalankan ini di sqlplus? Ekstrak mengembalikan instance XMLType, dan ditampilkan sesuai dengan panjang variabel, yang defaultnya adalah 80. Jika Anda meningkatkan nilainya, Anda dapat melihat URL lengkapnya.

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

Setelah meningkatkan nilai untuk variabel panjang,

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

Anda dapat menggunakan fungsi getStringVal untuk mengonversi XMLType ke varchar2, yang tidak bergantung pada variabel panjang.

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. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Bagaimana cara menulis / memperbarui gumpalan Oracle dengan cara yang andal?

  2. log pemicu oracle

  3. Pembaruan Patch Kritis Oracle – Oktober 2020

  4. Oracle Database Explorer:Pelatihan dan Akreditasi Gratis

  5. Penyembunyian angka &nls_parameter