How to use an Oracle Associative Array in a SQL query

前端 未结 2 1678
自闭症患者
自闭症患者 2020-12-15 11:47

ODP.Net exposes the ability to pass Associative Arrays as params into an Oracle stored procedure from C#. Its a nice feature unless you are trying to use the data contained

2条回答
  •  情书的邮戳
    2020-12-15 11:58

    I would create a database type like this:

    create type v2t as table of varchar2(30);
    /
    

    And then in the procedure:

    FOR i IN 1..associativeArray.COUNT LOOP
        databaseArray.extend(1);
        databaseArray(i) := associativeArray(i);
    END LOOP;
    
    OPEN refCursor FOR
    SELECT T.*
    FROM   SOME_TABLE T,
           ( SELECT COLUMN_VALUE V
             FROM   TABLE( databaseArray )
           ) T2
    WHERE  T.NAME = T2.V;
    

    (where databaseArray is declared to be of type v2t.)

提交回复
热议问题