Jason Vogel – Blog

September 15, 2006

Oracle SELECT with an array using an IN

Filed under: Oracle — jasonvogel @ 10:05 pm

SELECT with an array with an IN

declare

    – CREATE OR REPLACE TYPE PROD_TYPES.TYPE_NUMBER_ARRAY AS TABLE OF NUMBER
    nt_src     prod_types.type_number_array := PROD_TYPES.TYPE_NUMBER_ARRAY();    – Constructor     
    nt_dest     prod_types.type_number_array := PROD_TYPES.TYPE_NUMBER_ARRAY();    – Constructor     

begin

    – Test data (no order)
    select
        product_version_id
    bulk collect
    into
        nt_src
    from product_version v
    where v.product_version_id between 138120 and 140000;

    – select * from table(sys.dbms_debug_vc2coll(1,2,’a')) order by 1 desc
    
    – Data ordered
    select
        product_version_id
    bulk collect
    into nt_dest
    from
         product_version
    where
        product_version.product_version_id in (select column_value from table(cast(nt_src AS prod_types.type_number_array)))
    order by
        product_version.expiration_date2 desc,
        product_version.base_price desc,
        product_version.expiration_date2 desc;

    for i in nt_dest.first .. nt_dest.last loop
        dbms_output.put_line(to_char(nt_dest(i)));
    end loop;

    exception
        when others then
            dbms_output.put_line(‘sqlerrm : ‘||sqlerrm);
end;

Powered by Qumana

Advertisement

3 Comments »

  1. Gracias Jason, me ha servido de mucho.

    Comment by Toni — March 15, 2007 @ 2:38 pm

  2. very interesting, but I don’t agree with you
    Idetrorce

    Comment by Idetrorce — December 15, 2007 @ 2:27 pm

  3. Thanks for information.
    many interesting things
    Celpjefscylc

    Comment by celpjefscycle — January 12, 2008 @ 8:58 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.