sql >> データベース >  >> RDS >> Oracle

xml切り捨て値からのOracle抽出

    これをsqlplusで実行していますか? ExtractはXMLTypeインスタンスを返し、に従って表示されます。長い 変数。デフォルトは80です。値を増やすと、完全なURLが表示されます。

    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
    

    long変数の値を増やした後、

    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
    

    getStringVal関数を使用して、XMLTypeをvarchar2に変換できます。varchar2はlong変数に依存しません。

    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. スキーマに依存しないEntityFrameworkコードの最初の移行

    2. 条件付きリード/ラグ関数PostgreSQL?

    3. 単一のスキーマのみの洗練されたコード生成

    4. シェルスクリプトを使用してリモートMYSQLデータベースにデータを挿入する