Creating a function to return a table of records

Okay, I thought I knew how to do this but apparently not. I have a very complex query that connects multiple tables. I want to put the results of that query into a "table" (non-persistent) that can be passed to another procedure. So, I created an object/record that defines a single row in this table:
create or replace TYPE SHP_RECORD is OBJECT
(FIELD01 NUMBER(10),
FIELD02 NUMBER(10),
FIELD03 NUMBER(10),
FIELD04 NUMBER(10),
FIELD05 NUMBER(10),
FIELD06 VARCHAR2(200),
FILED07 NUMBER(10),
FIELD08 VARCHAR2(200),
FIELD09 NUMBER(10),
FIELD10 TIMESTAMP(6),
FIELD11 TIMESTAMP(6),
FIELD12 TIMESTAMP(6),
FIELD13 VARCHAR2(5),
FIELD14 NUMBER(10),
FIELD15 VARCHAR2(100),
FIELD16 VARCHAR2(4000),
FIELD17 VARCHAR2(1),
FIELD18 VARCHAR2(1));
Then I create another type that defines a table of SHP_RECORD:
Create or replace TYPE SHP_TABLE is TABLE of SHP_RECORD;
Now I have a function that puts the huge query into a text string (because it's got elements that change depending on what day of the week it's being run on so I have to keep it as a dynamic query. Now I want to run this query and put the results into a table. I've changed all the names to protect the innocent in this code snippet:
create or replace function get_SHP_data(p_cust_id IN NUMBER,
p_date IN TIMESTAMP) return SHP_TABLE as
begin
declare
shp_data_out SHP_TABLE;
TYPE shp_cur_type is REF CURSOR;
shp_cv shp_cur_type;
TYPE daily_query is VARRAY(7) of VARCHAR2(15);
query_values DAILY_QUERY;
day_index NUMBER;
old_program_id NUMBER;
chk_rundown NUMBER;
query_text VARCHAR2(3000);
row_index NUMBER;
program_freq_id NUMBER;
prog_seg_count NUMBER;
upload_seg_count NUMBER;
xfer_count NUMBER;
sched_count NUMBER;
bill_count NUMBER;
rcvr_text VARCHAR2(2000);
xmsn_start TIMESTAMP;
xmsn_end TIMESTAMP;
epi_status VARCHAR2(2000);
begin
query_values := daily_query('1, 3, 4, 12','1, 2, 5, 12','1, 2, 6, 12','1, 2, 7, 12','1, 2, 8, 12','1, 2, 9, 12','1, 3, 10, 12');
day_index := to_number(to_char(p_date,'D'));
query_text := {really ugly query here that includes concatinating a value from query_values as well as defines five bind variables numbered :1 through :5};
old_program_id := 0;
open shp_cv for query_text using p_date, p_date, p_date, p_date, p_cust_id;
fetch shp_cv bulk collect into shp_data_out;
close shp_cv;
end;
end;
Okay, the function compiles just fine. But when I try to run it I get:
select * from table(get_shp_data(226, SYSTIMESTAMP))
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got -
ORA-06512: at "SCHEMA.GET_SHP_DATA", line 69
The line it's blowing up on is "fetch ship_cv bulk collect into shp_data_out" I've checked and verified that the record/object structure SHP_RECORD matches in both type and order the values that are returned by the query. So...what gives? I've been beating my head against this particular problem for several days now and am no closer to a solution.
Any and all suggestions or corrections gratefully appreciated.
Oh, and this is being run in a 10g release 2 environment:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
HELP??!!

Hi,
Even though the fetch is seemingly taking the exact same types, Oracle will still need you to cast the resultset into the proper type.
Here's a short example of one way of doing it:
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.5.0
Connected as FSITJA
SQL>
SQL> create table my_table as select owner, table_name from all_tables where rownum <= 5;
Table created
SQL> create or replace type SHP_RECORD as object (owner varchar2(30), table_name varchar2(30));
  2  /
Type created
SQL> create or replace type SHP_TABLE as table of SHP_RECORD;
  2  /
Type created
SQL> create or replace function get_shp_data(p_owner in my_table.owner%type) return shp_table as
  2    shp_data_out shp_table;
  3    cur_shp sys_refcursor;
  4  begin
  5    open cur_shp for
  6      select cast (multiset(select owner, table_name
  7                              from all_tables
  8                             where owner = p_owner
  9                               and rownum <= 5) as shp_table)
10         from dual;
11    fetch cur_shp
12      into shp_data_out;
13    return shp_data_out;
14  end;
15  /
Function created
SQL> select * from table(get_shp_data('SYS'));
OWNER                          TABLE_NAME
SYS                            TABLE_PRIVILEGE_MAP
SYS                            SYSTEM_PRIVILEGE_MAP
SYS                            STMT_AUDIT_OPTION_MAP
SYS                            P$POK_CFG
SYS                            DUALYou might want to check on Pipelined table functions and perhaps the function result cache in the docs, as means to improve your performance.
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/tuning.htm#LNPLS01210
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/subprograms.htm#LNPLS00817

Similar Messages

  • How to create a function that returns multiple rows in table

    Dear all,
    I want to create a funtion that returns multiple rows from the table (ex: gl_balances). I done following:
    -- Create type (successfull)
    Create or replace type tp_gl_balance as Object
    PERIOD_NAME VARCHAR2(15),
    CURRENCY_CODE VARCHAR2(15),
    PERIOD_TYPE VARCHAR2(15),
    PERIOD_YEAR NUMBER(15),
    BEGIN_BALANCE_DR NUMBER,
    BEGIN_BALANCE_CR NUMBER
    -- successfull
    create type tp_tbl_gl_balance as table of tp_gl_balance;
    but i create a function for return some rows from gl_balances, i can't compile it
    create or replace function f_gl_balance(p_period varchar2) return tp_tbl_gl_balance pipelined
    as
    begin
    return
    (select gb.period_name, gb.currency_code, gb.period_type, gb.period_year, gb.begin_balance_dr, gb.begin_balance_cr
    from gl_balances gb
    where gb.period_name = p_period);
    end;
    I also try
    create or replace function f_gl_balance(p_period varchar2) return tp_tbl_gl_balance pipelined
    as
    begin
    select gb.period_name, gb.currency_code, gb.period_type, gb.period_year, gb.begin_balance_dr, gb.begin_balance_cr
    from gl_balances gb
    where gb.period_name = p_period;
    return;
    end;
    Please help me solve this function.
    thanks and best reguard

    hi,
    Use TABLE FUNCTIONS,
    [http://www.oracle-base.com/articles/9i/PipelinedTableFunctions9i.php]
    Regards,
    Danish

  • Certain Numbers templets allow you to drag and drop contacts to populate cell data, how can I create that functionality in my own tables?

    Certain Numbers templets allow you to drag and drop contacts to populate cell data, how can I create that functionality in my own tables?

    If you haven't come across the workarounds thread you may find helpful tips there on this and other ways to work with Numbers 3.
    ronniefromcalifornia discovered how to bring contacts into Numbers 3. As described in this post:
    "Open Contacts
    Select all the cards you want
    Copy
    In Numbers, in a table, select cell A1
    Paste
    Boom. Works great. Even brought in the pictures. Cool."
    So instead of drag and drop, just select in Contacts, copy, and paste into Numbers
    SG

  • I am trying to create  a function , which would retun table type.

    Gurus,
    I am trying to create a function which would return a nested table with 3
    columns of a table as a type.
    my query is like
    select col1,col2,col3 from table_1;
    I am kinda newbie in Oracle and have never used collections.
    Can you please guide ?

    >
    I am kinda newbie in Oracle and have never used collections.
    >
    Then you should start with the documentation
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/toc.htm
    Chapter 5 is all about Using PL/SQL collections and has examples
    >
    I am trying to create a function which would return a nested table with 3
    columns of a table as a type.
    >
    That isn't enough of a description to know what you are trying to do or how you plan to use the function. The query you provided has no relation to the question you ask.
    Are you asking about pipelined functions? Here is an example of that
    -- type to match emp record
    create or replace type emp_scalar_type as object
      (EMPNO NUMBER(4) ,
       ENAME VARCHAR2(10),
       JOB VARCHAR2(9),
       MGR NUMBER(4),
       HIREDATE DATE,
       SAL NUMBER(7, 2),
       COMM NUMBER(7, 2),
       DEPTNO NUMBER(2)
    -- table of emp records
    create or replace type emp_table_type as table of emp_scalar_type
    -- pipelined function
    create or replace function get_emp( p_deptno in number )
      return emp_table_type
      PIPELINED
      as
       TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
        emp_cv EmpCurTyp;
        l_rec  emp%rowtype;
      begin
        open emp_cv for select * from emp where deptno = p_deptno;
        loop
          fetch emp_cv into l_rec;
          exit when (emp_cv%notfound);
          pipe row( emp_scalar_type( l_rec.empno, LOWER(l_rec.ename),
              l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno ) );
        end loop;
        return;
      end;
    select * from table(get_emp(20))

  • Creating a function and return something from an XML file

    Hi!
    I'm working with timeline actionscript. I want to create a function that loads my xmlfile and returns an xmlobject with the file's content.
    This is what I got so far:
    my_btn.addEventListener(MouseEvent.CLICK, getXML("myxml.xml")); //1067: Implicit coercion of a value of type void to an unrelated type Function.
    function getXML(fn:String):void{
         var infoLoader:URLLoader = new URLLoader();
         infoLoader.addEventListener(Event.COMPLETE, xmlLoaded);
         infoLoader.load(new URLRequest(fn));
         var myXML:XML = xmlLoaded(); //1136: Incorrect number of arguments.  Expected 1.
         trace(myXML);
    function xmlLoaded(e:Event):XML{
         return e.target.data;
         //trace(e.target.data);
    Can anyone take a look and perhaps point me in the right direction?
    Thanks

    I have never used a listcomponent, so I can only help with the steps before filling it with data.
    I think you should at start of your application load the XML with filenames and just after it's completed, e.g. in Event.COMPLETE handler, load all other XMLs looping through filenamesXML, like this
    var filenamesXML:XML;
    var XMLsToLoad:uint = 0;
    function filenamesXMLLoaded(e:Event):void
         filenamesXML = XML(e.target.data);
         XMLsToLoad =  filenamesXML.filenames.children().length();
         for (var i:uint =1; i < filenamesXML.filenames.children().length(); i++)
                  getXML( filenamesXML.filenames.children()[i] ); // the function from my previous post, don't forget to implement it
    //modify the minor xml load handler from the previous post
    function xmlLoaded(e:Event):void
         var loadedXML:XML = XML(e.target.data);   
         xmlArray.push(loadedXML);
         XMLsToLoad--;
    //assign the one click handler to all buttons, a loop here would be quite handy
    function clickHandler(e:MouseEvent):void
         if (XMLsToLoad == 0) //check if all xmls have been completely loaded
              switch (e.target.name) // swith by clicked button's instance name
                   case "button_1":
                        // here you have to implement supplying listcomponent with data, I think a loop again will be a good idea
                        break;
                   case "button_2":
                        // ibid.
                        break;
    Regards,
    gc

  • How to create ENQUEUE function module for s567 table

    Hi Experts,
    Anyone Plz tell the steps how to create a ENQUEUE function module for the table s567.
    Its somewht urgent, plz help me.
    <REMOVED BY MODERATOR>
    Mohana
    Edited by: Alvaro Tejada Galindo on Mar 10, 2008 4:21 PM

    Hi,
    You can create a lock on a object of SAP thorugh transaction SE11 and enter any meaningful name start with EZ Example EZTEST_LOCK.
    Use: you can see in almost all transaction when you are open an object in Change mode SAP could not allow to any other user to open the same object in change mode.
    Example: in HR when we are enter a personal number in master data maintainance screen SAP can't allow to any other user to use same personal number for changes.
    Technicaly:
    When you create a lock object System automatically creat two function module.
    1. ENQUEUE_<Lockobject name>. to insert the object in a queue.
    2. DEQUEUE_<Lockobject name>. To remove the object is being queued through above FM.
    You have to use these function module in your program.
    Hope this will give a basic idea.
    Regards
    Sudheer

  • How Can I Create a Function to Return to a Specific Menu on DVD Studio Pro?

    Hello, I am currently building a DVD for a TV series I created while in college, and I'm having trouble figuring out how to create a function within the DVD that lets the user select the title or menu buttons on their remotes and have that return them either to a) the main menu or b) the menu they were just at, ie episode select or chapter select. Any help is appreciated! Thanks!

    Thanks for the help. I'm still a little confused on how to get it select which menu that I would like to return to.

  • Memory leak in JCO when calling an ABAP-function that returns larg tables

    Hello everybody,
    I think discovered a memory leak in JCO when the calling functionions that have exporting tables with large datasets. For example the ABAP-function RFC_READ_TABLE, which in this example I use to retrieve data from a table called "RSZELTTXT", which contains ~ 120000 datasets. RFC_READ_TABLE exports the data as table "DATA".
    Here a simple JUnit test:
    http://pastebin.ca/1420451
    When running it with Sun Java 1.6 with standard heap size of 64mb I get a heapsize OutOfMemory error:
    http://pastebin.ca/1420472
    Looking at the heap dump (which I unfortunately cannot post here, because of it' size), I can see that I've 65000 char[512] array objects in my heap, which don't get cleaned up. I think, each char[512] array stands for one dataset in the exporting table "DATA", since the table contains 120000 datasets, the heap is full after the first 65000 datasets are parsed. Apparently, JCO tries to read all datasets in memory instead of justing reading the dataset to which the pointer (JCoTable.setRow(i)) currently points to and releasing it from memory after the pointer moves forward ...
    Did anybody else experience this?
    Is SAP going to remove to issue in upcoming versions of JCO?
    regards Samir

    Hi,
       Check Below links
    1) How To Analyze Performance Problems JCO
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/3fbea790-0201-0010-6481-8370ebc3c17d
    2) How to Avoid Memory Leaks 
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c3e598fe-0601-0010-e990-b8622840c8c2
    Salil...
    Edited by: salil chavan on Jun 2, 2009 5:21 AM

  • Call a function that returns a table

    Hi all,
    I create a partner link that calls a function from the database. That function returns a type defined in the database that is a table:
    ceate or replace type tablela_de_ids is table of number
    the XSD created is:
    <schema targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/db/IGIF/WC01/PESQUISA_UT/" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:db="http://xmlns.oracle.com/pcbpel/adapter/db/IGIF/WC01/PESQUISA_UT/">
    <element name="InputParameters">
    <complexType>
    <sequence>
    <element name="P_NIR" type="decimal" db:index="1" db:type="NUMBER" minOccurs="0" nillable="true"/>
    <element name="P_NOME_COMPLETO" type="string" db:index="2" db:type="VARCHAR2" minOccurs="0" nillable="true"/>
    <element name="P_SEXO" type="string" db:index="3" db:type="VARCHAR2" minOccurs="0" nillable="true"/>
    <element name="P_DATA_NASC" type="dateTime" db:index="4" db:type="DATE" minOccurs="0" nillable="true"/>
    <element name="P_NATURALIDADE" type="string" db:index="5" db:type="VARCHAR2" minOccurs="0" nillable="true"/>
    </sequence>
    </complexType>
    </element>
    <element name="OutputParameters">
    <complexType>
    <sequence>
    <element name="PESQUISA_UT" type="db:TABELA_DE_IDS" db:index="0" db:type="Array"
    minOccurs="1" nillable="true"/>
    </sequence>
    </complexType>
    </element>
    <complexType name="TABELA_DE_IDS" >
    <sequence>
    <element name="PESQUISA_UT_ITEM" type="decimal" db:type="NUMBER" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
    </sequence>
    </complexType>
    </schema>
    I'm having a problem whit the output.
    When the function returs only a number, it's correct...
    <messages>
    - <WC01_Pesquisa_Ut_InputVariable>
    - <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="InputParameters">
    - <InputParameters xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/IGIF/WC01/PESQUISA_UT/">
    <P_NIR xmlns="">165968274</P_NIR>
    <P_NOME_COMPLETO xmlns="">maria eduarda oliveira</P_NOME_COMPLETO>
    <P_SEXO xmlns="">Feminino</P_SEXO>
    <P_DATA_NASC xmlns="">1944-09-05</P_DATA_NASC>
    <P_NATURALIDADE xmlns=""/>
    </InputParameters>
    </part>
    </WC01_Pesquisa_Ut_InputVariable>
    - <WC01_Pesquisa_Ut_OutputVariable>
    - <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="OutputParameters">
    - <db:OutputParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:db="http://xmlns.oracle.com/pcbpel/adapter/db/IGIF/WC01/PESQUISA_UT/">
    - <PESQUISA_UT>
    <PESQUISA_UT_ITEM>189442</PESQUISA_UT_ITEM>
    </PESQUISA_UT>
    </db:OutputParameters>
    </part>
    <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="response-headers">[]
    </part>
    </WC01_Pesquisa_Ut_OutputVariable>
    </messages>
    but when the function returns more than one, I can't see the result:
    <messages>
    - <WC01_Pesquisa_Ut_InputVariable>
    - <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="InputParameters">
    - <InputParameters xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/IGIF/WC01/PESQUISA_UT/">
    <P_NIR xmlns="">123456789</P_NIR>
    <P_NOME_COMPLETO xmlns="">ferreira</P_NOME_COMPLETO>
    <P_SEXO xmlns="">Feminino</P_SEXO>
    <P_DATA_NASC xmlns="">1944-09-05</P_DATA_NASC>
    <P_NATURALIDADE xmlns=""/>
    </InputParameters>
    </part>
    </WC01_Pesquisa_Ut_InputVariable>
    - <WC01_Pesquisa_Ut_OutputVariable>
    - <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="OutputParameters">
    - <db:OutputParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:db="http://xmlns.oracle.com/pcbpel/adapter/db/IGIF/WC01/PESQUISA_UT/">
    <PESQUISA_UT/>
    </db:OutputParameters>
    </part>
    <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="response-headers">[]
    </part>
    </WC01_Pesquisa_Ut_OutputVariable>
    </messages>
    Any ideia?
    Thanks in advance.
    Carla

    When you invoke the service from the Enterprise Manager, does it give output?

  • Web Service created from Function Module with output tables

    Hello,
    I created a web service from a custom function module.  This Function module has some export parameters and one table.
    The table parameter returns a list of data for selection.
    When I execute the function module, everything is returned fine.
    When I call the web service, the export parameters are returned but the table is empty.
    Has anyone encountered that kind of issue?
    Thanks!
    Laurent

    Please check the following few things while testing the WS:
    - Test the WS with WS Navigator (accessible from transaction WSADMIN or http://<server host>:<port>/wsnavigator/enterwsdl.html).
    - While doing the test, give the exact no. of digit if there is some input parameter (with 0 padding if necessary).
    - Make sure the "SKIP" check box against the table parameter is NOT checked.
    Regards
    Nilay

  • Create one function which return boolean

    I want to write one function means if the resource status is cv locked in any one of the project,then automatically the status of this resource changed to unavailble for other projects.
    Indicate that we can nominate the same resource for different projects but after cv lock that resources made unavailbale for other projects.
    Require coding
    Edited by: user12877889 on Jun 28, 2010 5:12 AM

    Hi,
    Well how to say, i suggest you to start with theses documentations:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/toc.htm
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/toc.htm
    Thenyou'll probably have a better idea of what's an Oracle DB. After that comme back and describe the tools you're using and what's your requirements (what's you want to do, for what purpose...) then may be we'll be able to help you ..

  • Function modules to edit table's record

    Hi, thanks in advance. I have two questions:
    1. I call function 'STC1_FULLSCREEN_TABLE_CONTROL' to edit a table, the problem is fieldnames are not displayed, all emptys. Please check below calling.
    CALL FUNCTION 'STC1_FULLSCREEN_TABLE_CONTROL'
           EXPORTING
                HEADER = p_table
                tabname = p_table
                endless = 'X'
                no_button = space
           IMPORTING
                okcode = w_okcode
           TABLES
                 nametab = it_dfies
                 TABLE = <itab>
                 fielddif = it_fdiff
                 modif_table = <ntab>
           EXCEPTIONS
                 OTHERS = 1.
    2. The second question is above function module is to edit a table in full screen style, multiple record lines are displayed. Could you please tell me which function module can be called to only edit one record in the screen?
    Thanks.
    Tom

    Hello Tom
    Use the following code before calling the function.
    loop at IT_DFIES into is_dfies.
        if is_dfies-reptext is initial.
          select single scrtext_s into is_dfies-reptext from ddftx where tabname = is_dfies-tabname
                                                                     and fieldname = is_dfies-fieldname
                                                                     and ddlanguage = sy-langu.
          IF sy-subrc = 0 and is_dfies-reptext is initial.
            select single scrtext_m into is_dfies-reptext from ddftx where tabname = is_dfies-tabname
                                                                       and fieldname = is_dfies-fieldname
                                                                       and ddlanguage = sy-langu.
            IF sy-subrc = 0 and is_dfies-reptext is initial.
              select single scrtext_l into is_dfies-reptext from ddftx where tabname = is_dfies-tabname
                                                                         and fieldname = is_dfies-fieldname
                                                                         and ddlanguage = sy-langu.
            endif.
          endif.
          If is_dfies-reptext is initial.
            select single fieldtext into is_dfies-reptext from ddftx where tabname = is_dfies-tabname
                                                                       and fieldname = is_dfies-fieldname
                                                                       and ddlanguage = sy-langu.
          ENDIF.
          If is_dfies-reptext is initial.
            is_dfies-reptext = is_dfies-fieldname.
          ENDIF.
          modify it_dfies from is_dfies .
        endif.
      endloop.
    I hope that could help
    Regards
    dstj

  • Calling a PL/SQL function returning Netsed Table Rows

    Hi,
    I am trying to call a Function which returns Nested Table rows (as Out Parameter) in Java .
    When I am trying to use
    pstmt.registerOutParameter(3, OracleTypes.OTHER);
    to capture the Out parameter in Java code , I get the follwoing error :
    java.sql.SQLException: Invalid column type
    I have even tried using OracleTypes.JAVA_OBJECT ,but I get the same error.
    If I use OracleTypes.JAVA_STRUCT I get
    java.sql.SQLException: Parameter Type Conflict: sqlType=2008
    error.
    Please help .
    Am I doing the right thing ?
    Thanks in advance.
    Ninad

    http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/jdbc20/jdbc20.html

  • Function which returns multiple values that can then be used in an SQL Sele

    I'd like to create a function which returns multiple values that can then be used in an SQL Select statement's IN( ) clause
    Currently, the select statement is like (well, this is a very simplified version):
    select application, clientid
    from tbl_apps, tbl_status
    where tbl_apps.statusid = tbl_status.statusid
    and tbl_status.approved > 0;
    I'd like to pull the checking of the tbl_status into a PL/SQL function so my select would look something like :
    select application, clientid
    from tbl_apps
    where tbl_apps.statusid in (myfunction);
    So my function would be running this sql:
    select statusid from tbl_status where approved > 0;
    ... will return values 1, 5, 15, 32 (and more)
    ... but I haven't been able to figure out how to return the results so they can be used in SQL.
    Thanks for any help you can give me!!
    Trisha Gorr

    Perhaps take a look at pipelined functions:
    Single column example:
    SQL> CREATE OR REPLACE TYPE split_tbl IS TABLE OF VARCHAR2(32767);
      2  /
    Type created.
    SQL> CREATE OR REPLACE FUNCTION split (p_list VARCHAR2, p_delim VARCHAR2:=' ') RETURN SPLIT_TBL PIPELINED IS
      2      l_idx    PLS_INTEGER;
      3      l_list   VARCHAR2(32767) := p_list;
      4      l_value  VARCHAR2(32767);
      5    BEGIN
      6      LOOP
      7        l_idx := INSTR(l_list, p_delim);
      8        IF l_idx > 0 THEN
      9          PIPE ROW(SUBSTR(l_list, 1, l_idx-1));
    10          l_list := SUBSTR(l_list, l_idx+LENGTH(p_delim));
    11        ELSE
    12          PIPE ROW(l_list);
    13          EXIT;
    14        END IF;
    15      END LOOP;
    16      RETURN;
    17    END SPLIT;
    18  /
    Function created.
    SQL> SELECT column_value
      2  FROM TABLE(split('FRED,JIM,BOB,TED,MARK',','));
    COLUMN_VALUE
    FRED
    JIM
    BOB
    TED
    MARK
    SQL> create table mytable (val VARCHAR2(20));
    Table created.
    SQL> insert into mytable
      2  select column_value
      3  from TABLE(split('FRED,JIM,BOB,TED,MARK',','));
    5 rows created.
    SQL> select * from mytable;
    VAL
    FRED
    JIM
    BOB
    TED
    MARK
    SQL>Multiple column example:
    SQL> CREATE OR REPLACE TYPE myrec AS OBJECT
      2  ( col1   VARCHAR2(10),
      3    col2   VARCHAR2(10)
      4  )
      5  /
    Type created.
    SQL>
    SQL> CREATE OR REPLACE TYPE myrectable AS TABLE OF myrec
      2  /
    Type created.
    SQL>
    SQL> CREATE OR REPLACE FUNCTION pipedata(p_str IN VARCHAR2) RETURN myrectable PIPELINED IS
      2    v_str VARCHAR2(4000) := REPLACE(REPLACE(p_str, '('),')');
      3    v_obj myrec := myrec(NULL,NULL);
      4  BEGIN
      5    LOOP
      6      EXIT WHEN v_str IS NULL;
      7      v_obj.col1 := SUBSTR(v_str,1,INSTR(v_str,',')-1);
      8      v_str := SUBSTR(v_str,INSTR(v_str,',')+1);
      9      IF INSTR(v_str,',')>0 THEN
    10        v_obj.col2 := SUBSTR(v_str,1,INSTR(v_str,',')-1);
    11        v_str := SUBSTR(v_str,INSTR(v_str,',')+1);
    12      ELSE
    13        v_obj.col2 := v_str;
    14        v_str := NULL;
    15      END IF;
    16      PIPE ROW (v_obj);
    17    END LOOP;
    18    RETURN;
    19  END;
    20  /
    Function created.
    SQL>
    SQL> create table mytab (col1 varchar2(10), col2 varchar2(10));
    Table created.
    SQL>
    SQL> insert into mytab (col1, col2) select col1, col2 from table(pipedata('(1,2),(2,3),(4,5)'));
    3 rows created.
    SQL>
    SQL> select * from mytab;
    COL1       COL2
    1          2
    2          3
    4          5

  • TABLE  FUNCTION OR CAST WITH TABLE FUNCTION

    Consider following scenario:
    I've a function which returns nested table of employees.
    I am calling this function in some other procedure and building a query dynamically.
    Sample code looks like
    CREATE OR REPLACE  PROCEDURE TEST_PROC( P_EMP_ID   IN   NUMBER,
                                            O_EMP_LIST OUT  SYS_REFCURSOR) IS
    v_tbl_emp_id       tbl_emp_id;
    begin
    v_tbl_emp_id :=  fn_get_usr_list (P_EMP_ID);--fetches employee id  reporting to given emp id
    v_select_clause :=
             'SELECT EMP_NO,EMP_NAME,DEPT_NO';
    v_from_clause := ' FROM EMP';
    v_where_clause1 :=
                ' WHERE emp_no IN (
                          SELECT  COLUMN_VALUE
                                     FROM TABLE
                                             (CAST
                                                 (:v_tbl_emp_id AS tbl_emp_id
    --AND I AM APPENDING AND CLAUSES BASED ON VARIOUS CONDITION
    v_qry :=     v_select_clause  || v_from_clause|| v_where_clause1;
    OPEN O_EMP_LIST FOR v_qry USING v_tbl_emp_id;
    END TEST_PROC;I CAN REWRITE THE SAME CODE AS
    CREATE OR REPLACE  PROCEDURE TEST_PROC( P_EMP_ID   IN   NUMBER,
                                            O_EMP_LIST OUT  SYS_REFCURSOR) IS
    begin
    v_select_clause :=
             'SELECT EMP_NO,EMP_NAME,DEPT_NO';
    v_from_clause := ' FROM EMP';
    v_where_clause1 :=
                ' WHERE emp_no IN (
                          SELECT  COLUMN_VALUE
                                     FROM TABLE(fn_get_usr_list (:P_EMP_ID)))';
    --AND I AM APPENDING AND CLAUSES BASED ON VARIOUS CONDITION
    v_qry :=     v_select_clause  || v_from_clause|| v_where_clause1;
    OPEN O_EMP_LIST FOR v_qry  USING P_EMP_ID;
    END TEST_PROC;Now I would like to know which one performs better
    USING TABLE ALONE OR USING CAST ALONG WITH THE TABLE FUNCTION?
    AND PLEASE HELP ME ON FORMATTING CODE.
    I've added tags still its not formatting!!
    Thanks,
    NM
    Edited by: user10862473 on Apr 11, 2011 12:14 AM
    Edited by: BluShadow on 11-Apr-2011 09:13
    fixed {noformat}{noformat} tags

    To be sure which is better you will have to test them both. You can use either AUTOTRACE or Oracle trace (tkprof) to get run metrics - system resources used when running both versions of the query. AUTOTRACE won't provide CPU information, but if you can find the qieries in (G)V$SQL you can find it there. Oracle trace is more effort but should provide more metrics. I could do it if I have privileges :(..
    All I can do is check the time taken by the both procedures using set timing on, which gives same result for both.
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.07Thanks,
    NM

Maybe you are looking for

  • Error while using Recruitment application in ESS Portal

    Hi Experts, We are facing  two   issues when we are using recruitment application. By this applicaton,the concerned can raise a requirement to the recruitment dept. Some users are uanble to use the application. After filling the data,some users are g

  • Security breach - keychain and device not de-registered

    I recently was given an iPad 2 The problem is that the device is registered to someone else and the keychain is or looks to be part of someone else network.  Is there a chance that this's iPad could be accessed remotely and all my data could be viewe

  • I only have audio for the videos on apple's website using Safari?

    I can only hear the audio on apple's website to their videos.  I have the newest quicktime update and I'm not sure why it won't play.  Any thoughts or suggestions?

  • SDV on a Hi Def Monitor

    I recently created an in-store video for one of my clients. It had been running on a standard def monitor but they have remodeled and added a big honking 42" hi def flat screen TV...and the film looks really bad running on this monitor. The film was

  • ABAP/xi dummy projects

    Hey Guys It might not be the best place for this question but i guess i might get some help here.i am currently working in C/C++ and am now trying to move in the SAP world,i have studied  the basic concepts of ABAP and XI and this forum has helped me