Home > Blogroll, sql > predefined collections

predefined collections

December 5th, 2007

If I need to generate 3 rows called AAA, BBB, CCC, I could use dual and union all. Another method is to use Extensibility Types

select * from table
   (sys.ODCIVarchar2List('AAA','BBB','CCC'));

COLUMN_VALUE
------------
AAA
BBB
CCC

Bookmark and Share

  1. December 5th, 2007 at 19:06 | #1

    Nice trick.

  2. Gary
    December 6th, 2007 at 00:25 | #2

    I’ve used the following, which is also available in 9iR2:
    select * from table(sys.dbms_debug_vc2coll(’A',’B',’C'));
    This one is a TABLE OF VARCHAR2(1000), where ODCIVarchar2List is a VARRAY(32767) OF VARCHAR2(4000), so yours does give more space.

  3. DJ
    December 6th, 2007 at 01:41 | #3

    Come on, it takes a single SQL to create your own defined types. Why rely on system types that may change in the next release? One less thing to check for upgrade.

  4. December 6th, 2007 at 11:03 | #4

    DJ,
    Why should a SQL statement depend on a type, when there is a documented datatype which is not supposed to change in next release (because it is documented). Oracle cannot remove features in a next release without notice. I would say it is OK to rely on them because *they are documented*

    Those extensibility types also exist for date, numbers and raw.

    Gary,
    How could you say my one use more space? 32767 is a limit. Also varchar2(1000) is a meaningless constraint on varchar2, 4000 is the maximum. Could you show the difference in memory usage?

    But true, those extensibility types are documented only in 10gR2 and 11gR1. So in 9iR2, dbms_debug_vc2coll sounds possible

  5. December 6th, 2007 at 12:55 | #5

    I made a test Garry and it seems you are right about memory usage.

    
    select * from table(sys.ODCIVarchar2List('AAA','BBB','CCC'))
    
    COLUMN_VALUE                                                                    
    ------------
    AAA                                                                             
    BBB                                                                             
    CCC                                                                             
    
    select * from table(sys.dbms_debug_vc2coll('AAA','BBB','CCC'))
    
    COLUMN_VALUE                                                                    
    ------------
    AAA                                                                             
    BBB                                                                             
    CCC                                                                             
    
    select sql_text,sharable_mem,persistent_mem,runtime_mem 
    from v$sqlarea 
    where sql_text like '%AAA%' 
    and sql_text not like '%sharable%'
    
    SQL_TEXT                                                                        
    --------
    SHARABLE_MEM PERSISTENT_MEM RUNTIME_MEM
    ------------ -------------- -----------
    select * from table(sys.ODCIVarchar2List('AAA','BBB','CCC'))                    
           13582          13752       12864
                                                                                    
    select * from table(sys.dbms_debug_vc2coll('AAA','BBB','CCC'))                  
           13584           4752        3864
                                                                                    
    

  6. Chris
    December 7th, 2007 at 11:09 | #6

    What imho really sucks is that oracle is not capable of producing a set of reusable components for pl/sql development. E.g., there should be a goddamn standard table of varchar2(4000) that everybody uses! Well, they’d better get a better name ;-)

  7. December 7th, 2007 at 18:36 | #7

    Some ODCI varrays existed in 9i, like ODCINUMBERLIST. However, I found them documented only in 10gR2

  8. July 18th, 2008 at 20:03 | #8

    Nice trick , thanks…

  1. No trackbacks yet.