Return a Collection of a function

Hello oracle,

our Java developer calls a PL/SQL function and he gets a VARCHAR in return, that works fine so far. Now I would like to return a collection. But I don't know how to do it, since I need to define the collection inside the function. Maybe it's a simple task, but I don't know where start return a collection. Any suggestions or a link, maybe it's not possible at all?

Ikrischer

Yes it is possible, you must create a TYPE and then returning a TYPE in your service, see the very simplistic example below, once you have a level of database TYPE you can reuse:

SQL> create or replace type t_varchar2 is table of varchar2(4000)
  5  /

Type created.

SQL> create or replace function f_return_collection return t_varchar2
  2  is
  3  lt_varchar2 t_varchar2 := t_varchar2();
  4  begin   ---populate colleciton with some dummy data
  5  for i in 1..10 loop
  6      lt_varchar2.extend;
  7      lt_varchar2(i) := to_char(i)||'_index';
  8  end loop;
  9  return lt_varchar2;
 10  end;
 11  /

Function created.

SQL> set serveroutput on
  1  declare
  2  my_coll t_varchar2;
  3  begin
  4  my_coll := f_return_collection; ---call the function which returns the populated collection
  5  for i in 1..my_coll.count loop
  6      dbms_output.put_line(my_coll(i));
  7  end loop;
  8  end;
  9  /
1_index
2_index
3_index
4_index
5_index
6_index
7_index
8_index
9_index
10_index

PL/SQL procedure successfully completed.

Hope this is what your looking for...

Thank you
Paul

Tags: Database

Similar Questions

  • Returns the Collection using the table function

    Hello

    I'm trying to return a collection with registration type using the function table but face some problems.

    Could someone help me with this.
    SUNNY@11gR1> create or replace package test_pack as
      2  type rec_typ is record (
      3  empname varchar2(30),
      4  empage number(2),
      5  empsal number(10));
      6  type nest_typ is table of rec_typ;
      7  function list_emp return nest_typ;
      8  end;
      9  /
    
    Package created.
    
    Elapsed: 00:00:00.01
    SUNNY@11gR1> create or replace package body test_pack is
      2  function list_emp return nest_typ is
      3  nest_var nest_typ := nest_typ();
      4  begin
      5  nest_var.extend;
      6  nest_var(nest_var.last).empname := 'KING';
      7  nest_var(nest_var.last).empage := 25;
      8  nest_var(nest_var.last).empsal := 2500;
      9  nest_var.extend;
     10  nest_var(nest_var.last).empname := 'SCOTT';
     11  nest_var(nest_var.last).empage := 22;
     12  nest_var(nest_var.last).empsal := 3500;
     13  nest_var.extend;
     14  nest_var(nest_var.last).empname := 'BLAKE';
     15  nest_var(nest_var.last).empage := 1;
     16  return nest_var;
     17  end;
     18  end;
     19  /
    
    Package body created.
    
    Elapsed: 00:00:00.01
    SUNNY@11gR1> select * from table(test_pack.list_emp);
    select * from table(test_pack.list_emp)
                        *
    ERROR at line 1:
    ORA-00902: invalid datatype
    
    
    Elapsed: 00:00:00.01
    SUNNY@11gR1>
    Kind regards
    Sunny

    Hello

    I had to look, because I didn't know the difference. If you use a function in the pipeline, then Oracle will create the implicit type. Take a look at the types:

    select object_name from user_objects where object_type ='TYPE';
    

    There are now objects that you create yourself, having PLSQL in name.

    If you try your first example, you will see it will be no object created by implicit Oracle, so you must declare yourself in SQL.

    Herald tiomela
    Superconsult.nl

  • Select from 2 dimensions collection returned by a pipeline-table-function

    With the help of 10 gr 2

    A pipeline function returns a collection of an object oriented sub-collection:


    TYPE TXT_ARRAYTYPE IS TABLE OF THE VARCHAR2 (2000);

    type txt2dtable_objtype as object)
    txt2dtable txt_arraytype;

    type txt2dtable_arraytype as the txt2dtable_objtype table;


    FUNCTION getTxtList (start_date IN DATE) RETURN PIPELINED txt2dtable_arraytype
    ....



    How can I select from the function for each element varchar2 grouped by line number (the top-level collection) txt2dtable_arraytype?

    Example:

    Text of RowNum
    1 Hello
    1 World
    2 my
    2 name
    2 is
    2 Nuerni!
    3 How
    ....


    A select statement can be used for an external, OIC - / JDBC / follow App would be great!

    Any ideas?

    Kind regards
    Nuerni

    Something like this:

    SQL>create type txt_arraytype is table of varchar2(2000)
      2  /
    
    Type created.
    
    SQL>create type txt2dtable_objtype as object ( txt2dtable txt_arraytype )
      2  /
    
    Type created.
    
    SQL>create type txt2dtable_arraytype as table of txt2dtable_objtype
      2  /
    
    Type created.
    
    SQL>create or replace FUNCTION getTxtList (start_date in date)
      2  return txt2dtable_arraytype pipelined
      3  is
      4  begin
      5    pipe row( txt2dtable_objtype( TXT_ARRAYTYPE( 'Hello', 'World' ) ) );
      6    pipe row( txt2dtable_objtype( TXT_ARRAYTYPE( 'My', 'name', 'is', 'Anton' ) ) );
      7    pipe row( txt2dtable_objtype( TXT_ARRAYTYPE( 'And', 'this', 'is', 'an', 'example' ) ) );
      8    return;
      9  end;
     10  /
    
    Function created.
    
    SQL>
    SQL>select rn, y.column_value
      2  from ( select rownum rn
      3              , object_value
      4         from table( getTxtList( sysdate ) )
      5       ) x
      6     , table( x.object_value.txt2dtable ) y
      7  /
    
            RN COLUMN_VALUE
    ---------- -----------------------------------------------------------------------------------------
             1 Hello
             1 World
             2 My
             2 name
             2 is
             2 Anton
             3 And
             3 this
             3 is
             3 an
             3 example
    
    11 rows selected.
    
    SQL>
    

    Anton

  • How to return multiple variables from a function

    Hello

    As seen below, I tried more then return a variable to a function, but I think I have a syntax problem...

    function hesapla3 (parameter1, parameter 2): (number & & Boolean) / / PROBLEM IS HERE, I have NEED of TWO VARIABLES to RETURN
    {
    var yenideger2:Number = new Number();
    var bol2:Boolean = new Boolean();
    yenideger2 = parameter1 + parameter 2;
    if(yenideger2>80) {bol2 = false ;}
    Return yenideger2;
    return bol2;
    trace (yenideger2);
    trace (bol2);
    }

    You can do it this way.

    You can combine the 2 to 1 as a var

    var tekdeger:String=yenideger2.toString()+"-"+bol2.toString();

    Return tekdeger;

    and then you can split and mount the value returned into variables that you want...

  • function that returns a collection

    var type record is (number, number of b);

    I have a function like:

    FN (val1, val2) return var

    I call this fn in a SQL statement and I need all the values in the type returned by the fn as:

    Select t1.col1, t2.col2, fn(t2.col3,t2.col4).a, fn(t2.col3,t2.col4).b
    from t1, t2
    where t1.col1 = t2.col1


    Someone please suggest how to retrieve the values returned by the fn in the SQL statement

    Oh and just to add to this example, if I wanted the individual values, I could do...

    SQL> ed
    Wrote file afiedt.buf
    
      1  select rownum, f_fn(rownum, rownum*2).a as a, f_fn(rownum, rownum*2).b as b
      2  from dual
      3* connect by rownum <= 5
    SQL> /
    
        ROWNUM          A          B
    ---------- ---------- ----------
             1          1          2
             2         16         16
             3        729        216
             4      65536       4096
             5    9765625     100000
    
    SQL>
    
  • Can we do a query returns a collection plsql?

    Im trying to develop a function that returns a table nested records to a sql query, but I get
    ORA-00932: inconsistent data types: expected - was -.
    ORA-06512: at "CDB_WEB. PIPE_RESULTS', line 38

    The original version of this function (which works) is a function in the pipeline is no longer usable we hit a bug with functions in pipeline oracle in our production server and need to try a workaround...

    It's what I've done:

    1. create the type of record and the nested in the schema table:

    Create the OBJECT IS of TXR_RECORD type
    (external_id VARCHAR2 (25),)
    source tank (3),
    info1 VARCHAR2 (4000).
    info2 VARCHAR2 (4000).
    Info3 VARCHAR2 (4000).
    info4 VARCHAR2 (4000));
    /
    CREATE the type txr_table IS TABLE OF THE txr_record;
    /

    2 update plsql function to populate the nested table:

    FUNCTION to CREATE or REPLACE pipe_results (p_external_id VARCHAR2,
    p_source VARCHAR2,
    P_FROM INTEGER,
    p_to INTEGER)
    RETURN txr_table
    IS

    l_txr txr_table: = txr_table();
    rettab txr_table: = txr_table();
    l_from INTEGER: = 0;
    l_to INTEGER: = 5;
    sqlstr varchar2 (4000): = NULL;


    TYPE cv_type IS REF CURSOR;
    CV1 cv_type;

    BEGIN

    sqlstr: = ' SELECT external_id, source, info1, info2, info3, info4
    OF xrefs_sptr
    WHERE source =: x (this reads: x without the gap in the code, but it appears as a smily face if I repeat here)
    AND external_id =: y
    ORDER BY info4';


    Cv1 OPEN for sqlstr HELP p_source, p_external_id;
    Cv1 FETCH BULK COLLECT INTO l_txr;
    Cv1 CLOSE;

    l_from: = p_from;
    l_to: = p_to;

    I'm IN p_from... p_to
    LOOP
    IF l_txr (i) IS NOT NULL
    THEN
    rettab.extend;
    rettab (i): = l_txr (i);
    END IF;
    END LOOP;

    return rettab;
    END;
    /


    3. so far, everything seems ok, but when I try and call it since sql:

    Select the source, info1, info2, info3, external_id, info4
    table (pipe_results ('PMC1687509', 'PMC', 1, 5));

    I get the error:

    table (pipe_results ('PMC1687509', 'PMC', 1, 5))
    *
    ERROR on line 2:
    ORA-00932: inconsistent data types: expected - was -.
    ORA-06512: at "CDB_WEB. PIPE_RESULTS', line 38


    Im sure Im overlooking something basic despite re-reading the documentation and plsql programming Im a bit confused... is it possible to do what I try without using a pipeline function?

    I agree with all your points and suggestions, and of course, this isn't a function in pipeline.

    But, as stated in the original post:

    user4208249 wrote:
    The original version of this function (which works) is a function in the pipeline is no longer can be used as we hit an oracle bug with pipeline functions in our
    production server and the need to try a workaround ...

    Of course, it would be preferable if this "Workaround" could use straight SQL and PL/SQL. So, we need a clarification of the o.p.: how to use the current pipeline function?

  • return index collection ArrayCollection-1 after updating in datagrid

    When I called data.refresh ();  arraycollection.getItemIndex (obj1) returns-1

    is anyway to make it work properly or work around?

    <? XML version = "1.0" encoding = "utf-8"? >

    "" < s:Application xmlns:fx = "http://ns.adobe.com/mxml/2009"

    "xmlns: s="library://ns.adobe.com/flex/spark"preinitialize ="application1_preinitializeHandler (event) ".

    xmlns:MX ="library://ns.adobe.com/flex/mx"minWidth = "955" = "600" xmlns:local = minHeight"*" > "

    < fx:Script >

    <! [CDATA]

    Import mx.collections.ArrayCollection;

    Import mx.collections.Sort;

    Import mx.events.FlexEvent;

    private var data: ArrayCollection collection;

    private var obj1:Object;

    protected function application1_preinitializeHandler(event:FlexEvent):void

    {

    obj1 = {'name': '1'}

    data = new ArrayCollection();

    data.addItem (obj1);

    data.addItem({"name":"2"});)

    trace (Data.GetItemIndex (obj1)); 0

    var sort: sort = new Sort();

    sort.compareFunction = nameSort;

    Data.sort = sort;

    data .filterFunction = null;

    Data.Refresh ();

    -1 trace (Data.GetItemIndex (obj1))

    }

    private void aa (): void {}

    }

    private void nameSort(m1:Object,_m2:Object,arr:Array=null):int {}

    Returns - 1;

    }

    []] >

    < / fx:Script >

    < fx:Declarations >

    < / fx:Declarations >

    < / s:Application >

    A comparison function sorts must return 1, 0 or - 1 on a consistent basis.  He

    cannot simply return-1.

  • Verity &amp; lt; cfsearch &amp; gt; Returns &amp; quot; collection is not &amp; quot; error - when the collection is

    I created a collection using the Coldfusion Administrator - and this shows when viewing of all collections. I also filled the collection using < cfindex > - by using a SQL query - and that seems to work well. He put 117 entries in the collection - and this appears also in the Coldfusion Administrator recoveries.

    The problem is when I try to search the collection with the < cfsearch > tag, it returns an error indicating "collection that you specified does not exist or is not registered with the ColdFusion Search Service."

    I can see the collection that I'm looking for is. Is there anything else I need to do to get the < cfsearch > function to find the collection? I tried to repair the collection, the collection optimization, even delete and recreate - nothing seems to work. I Specifies the full path to the collection in my cfsearch, so that shouldn't be the problem.

    Y at - it another command or feature, I need to run?

    Thank you!!! Pamela

    Quote:
    I Specifies the full path to the collection in my cfsearch

    Not sure if this is the problem. The path exists in the CFAdmin. You can see the name of the collection in the cfsearch tag.

    Code to see the attachment, you can do a cfdump to see what the results are returned.

  • Return incorrectly ActiveX control wrapper function

    Hi all

    Thank you for taking the time to read and respond (I hope).

    I work with an instrument driver that I created from a control ActiveX the ActiveX controller Wizard.  However, I have a function that does not return one of his arguments, but he will return to the other.  See below.

    The goal is to open a device called the EV2300.  GetFreeBoards() should return the number of devices (plates) found and the names of the rooms.  He finds and returns the number of thin devices (2 If two devices are connected, 1 if a connected device and 0 when no devices are connected), but where it does not return the names.  The character array passed as reference remains empty and no error is reported.

    char msgStr[256];
    char *BrdName;
    ERRORINFO error;
    CAObjHandle EV2300_Handle;
    int returnVal;
    long nBrdsFound = 0;
    
    mainpanel = LoadPanel (0, "TE_User_Interface.uir", MAIN_PANEL);
    
    GetObjHandleFromActiveXCtrl (mainpanel, MAIN_PANEL_BQ80XRW, &EV2300_Handle);
    
    BrdName = msgStr;
    
    returnVal = BQ_EV2300_GetFreeBoards (EV2300_Handle, &error, 16, &nBrdsFound, &BrdName);
    

    The wrapper function generated by the wizard:

    HRESULT CVIFUNC BQ_EV2300_GetFreeBoards (CAObjHandle objectHandle,                                         ERRORINFO *errorInfo,                                         long nNumBrdsToGet, long *nNumBrds,                                         char **listBrdNames){   HRESULT __result = S_OK;  unsigned int __paramTypes[] = {CAVT_LONG, CAVT_LONG | CAVT_BYREFI,                                   CAVT_CSTRING | CAVT_BYREFI};
    
     __result = CA_MethodInvokeEx (objectHandle, errorInfo, &BQ_IID_EV2300_,                                 0x7, CAVT_EMPTY, NULL, 3, __paramTypes,                               nNumBrdsToGet, nNumBrds, listBrdNames);
    
       return __result;}
    

    Using the same controller configuration and hardware ActiveX in VB6 works perfectly: the name of the EV2300 is returned, and I can't continue to use in other functions:

    Dim Bq80xRW1 As Bq80xRW
    Dim BrdName As String
    Dim nBrdsFound As Long
    
    Bq80xRW1.GetFreeBoards 16, nBrdsFound, BrdName
    

    Any ideas what I could do wrong?

    Something is definitely wrong, because the last two parameters are the two output parameters and yet they are being defined as input parameters. So either the ActiveX control has bad IDL inside or the ActiveX controller Assistant made a mistake.

    You might try a little experiment by changing two CAVT_BYREFI references in the table of __paramTypes to CAVT_BYREFO to see if that makes a difference. Rationale: for strings, CA_MethodInvokeEx has probably convert c type a BSTR string for the input parameters and BSTR chain C for output parameters. Though she doesn't think that a parameter is an output parameter, my guess is that it probably don't back conversion. For long (which are a native type of ActiveX) should not do all the conversions.

  • How to return an array from a function package

    It is a package, that give the type of table.

    But it does not work.

    create or replace package account_group is

    TYPE string_array IS the TABLE OF varchar2.

    function get_acc_by_vat_number (in_string varchar2) return string_array;

    end account_group;

    create or replace package body is account_group

    function get_acc_by_vat_number (in_string varchar2) return string_array is

    acc_array string_array;

    i the number;

    cursor c1 is

    (Select to_char (d.account_number) wiz_customer_descrip account_number d, wiz_customer_hp_life l

    where commercial_flag = 'Y '.

    and l.franchise_code! = 'F29'

    and d.account_number = l.account_number

    and id_3 = in_string - vat_number

    - and ssn ='08-09-002272' - company_reg_num

    UNION

    Select to_char (d.account_number) wiz_customer_descrip account_number d, wiz_customer_hp_life l

    where commercial_flag = 'Y '.

    and l.franchise_code = 'F29'

    and d.account_number = l.account_number

    and id_3 = in_string - vat_number

    - and ssn ='08-09-002272' - company_reg_num

    and there are

    (select 1 from WIZ_CUSTOMER_HP_OCCURRENCE p

    WHERE product_category_code in ('MID', "MVO")

    and p.account_number = l.account_number

    and p.service_address_id = l.service_address_id));

    Start

    I: = 0;

    for the news loop c1

    i: = i + 1;

    acc_array (i): = cur.account_number;

    end loop;

    Return acc_array;

    end;

    end account_group;

    Use the functions in pipeline, which give to the appellant, while the dataset is the treatment.

    create or replace package account_group is

    TYPE string_array IS the TABLE OF varchar2.

    function get_acc_by_vat_number (in_string varchar2) return string_array in pipeline;

    end account_group;

    create or replace package body is account_group

    function get_acc_by_vat_number(in_string varchar2) return pipeline string_array is

    acc_array string_array;

    i the number;

    cursor c1 is

    (Select to_char (d.account_number) wiz_customer_descrip account_number d, wiz_customer_hp_life l

    where commercial_flag = 'Y '.

    and l.franchise_code! = 'F29'

    and d.account_number = l.account_number

    and id_3 = in_string - vat_number

    - and ssn ='08-09-002272' - company_reg_num

    UNION

    Select to_char (d.account_number) wiz_customer_descrip account_number d, wiz_customer_hp_life l

    where commercial_flag = 'Y '.

    and l.franchise_code = 'F29'

    and d.account_number = l.account_number

    and id_3 = in_string - vat_number

    - and ssn ='08-09-002272' - company_reg_num

    and there are

    (select 1 from WIZ_CUSTOMER_HP_OCCURRENCE p

    WHERE product_category_code in ('MID', "MVO")

    and p.account_number = l.account_number

    and p.service_address_id = l.service_address_id));

    Start

    I: = 0;

    for the news loop c1

    pipe row (c.account_number);

    end loop;

    return;

    end;

    end account_group;

  • How to return a message of a function

    Hi gurus,
    I wrote the function on my database related to the return of the specific table voucherdate
    I want to return one message if other that this condition means that if vouchers No. is not there or if there is no null vouchertype is provided.

    my function is
    -------------------
    create or replace fn_get_voucherdate (v_vouchertype in varchar2, v_compcode in numbers)
    date of return
    as
    date of v_voucherdate;
    Start
    If v_vouchertype = "B - P" then
    Select max (voucherdate) from v_voucherdate
    from sometables where vouchertype = v_vouchertype and companycode = v_compcode;

    Return v_voucherdate;

    elsif v_vouchertype = "C - P" then
    Select max (voucherdate) from v_voucherdate
    from someothertables where vouchertype = v_vouchertype and companycode = v_compcode;

    Return v_voucherdate;

    elsif v_vouchertype = "C - R" then
    Select max (voucherdate) from v_voucherdate
    from someothertables where vouchertype = v_vouchertype and companycode = v_compcode;

    Return v_voucherdate;

    elsif v_vouchertype = s-P' then
    Select max (voucherdate) from v_voucherdate
    from someothertables where vouchertype = v_vouchertype and companycode = v_compcode;

    Return v_voucherdate;
    on the other
    return a message here;
    end if;

    but the message by not returning function showing no matter what return value error

    Please guide me how display a message to the user.

    Please answer...

    but the message by not returning function showing no matter what return value error

    as it is coded your function returns a DATE data type
    It cannot return any "message".

  • Return multiple values from a function in a SELECT statement

    I hope I've provided enough information here. If not, let me know what I'm missing.

    I create a view that will combine the information from several tables. Most are pretty simple, but there are a couple of columns in the view that I need to get by running a function within a package. Even if this is quite simple (I have a function named action_date in a package called rp, for example, that I can use to return the date that I need through SOME rp.action_date (sequence_number).

    Here is the question: I really need to return several bits of information of the same record (not only action_date, but also action_office, action_value, etc.)-a join of the tables will work not here, as I will explain below. I can, of course, perform a function separate for each statement, but this is obviously inefficient. Within the select statement of the view, however, I don't know how each of the values that I need to get back.

    For example, right now, I have:

    Table 1:
    sequence_number NUMBER (10),
    name varchar (30),
    ...

    Table2:
    Table1_seq NUMBER (10),
    action_seq NUMBER (10),
    action_date DATE,
    action_office VARCHAR (3),
    action_value VARCHAR (60),
    ...

    I can't just simply join Table1 and Table2 because I have to perform processing in order to determine the rows returned matching, I really need to select. If the package opens a cursor and treats each line until it finds the one I need.

    The following works but is ineffective since all calls to the package returns the columns of the same record. I don't know how to put all the values that I need in the SELECT statement.
    CREATE VIEW all_this_stuff AS
    SELECT sequence_number, name,
    RP.action_date (sequence_number) action_date,
    RP.action_office (sequence_number) action_office,
    RP.action_value (sequence_number) action_value
    FROM table1

    Is there a way to return multiple values in my SELECT statement or I'm going about this all wrong?

    Any suggestions?

    Thank you very much!

    Hello

    What you want is a Query of Top - N , what you can do using the ROW_NUMBER analytic function in a subquery, like this:

    WITH     got_rnum     AS
    (
         SELECT     action_seq, action_dt, action_office, action_type, action_value
         ,     ROW_NUMBER () OVER ( ORDER BY  action_date
                                   ,            action_seq
                             ,            action_serial
                           ) AS rnum
         FROM     table2
         WHERE     action_code     = 'AB'
         AND     action_office     LIKE 'E'     -- Is this right?
    )
    SELECT     action_seq, action_dt, action_office, action_type, action_value
    FROM     got_rnum
    WHERE     rnum     = 1
    ;
    

    As written, this returns a single line (at most).
    I suspect you'll actually get a rank for each group , where a group is defined by a value in a table in which you join.
    In this case, add a PARTITION BY clause to the ROW_NUMBER function.
    If post you a small example of data (CREATE TABLE and INSERT statements), I could show you exactly how.
    As I don't have your tables, I'll show you the use of the tables in the scott schema.
    This is a view containing data in the scott.dept table and also to scott.emp, but only for the highest employee in each Department (in other words, the employee whose oldest hire date). If there be a tie for the first hire date, while the candidate with the lowest empno is selected.

    CREATE OR REPLACE VIEW     senior_emp
    AS
    WITH     got_rnum     AS
    (
         SELECT     d.deptno
         ,     d.dname
         ,     e.empno
         ,     e.ename
         ,     e.hiredate
         ,     ROW_NUMBER () OVER ( PARTITION BY  d.deptno
                                   ORDER BY          e.hiredate
                             ,                e.empno
                           ) AS rnum
         FROM     scott.dept     d
         JOIN     scott.emp     e     ON     d.deptno     = e.deptno
    )
    SELECT     deptno
    ,     dname
    ,     empno
    ,     ename
    ,     hiredate
    FROM     got_rnum
    WHERE     rnum     = 1
    ;
    
    SELECT     *
    FROM     senior_emp
    ;
    

    Output:

    .    DEPTNO DNAME               EMPNO ENAME      HIREDATE
    ---------- -------------- ---------- ---------- ---------
            10 ACCOUNTING           7782 CLARK      09-JUN-81
            20 RESEARCH             7369 SMITH      17-DEC-80
            30 SALES                7499 ALLEN      20-FEB-81
    

    Moreover, one of the conditions to the query you posted has been

    action_office     LIKE 'E'
    

    which equals

    action_office     = 'E'
    

    (AS is always equivalent to = if the string that follows AS does not contain the winning cards.)
    Did you mean say that or did you mean something like this:

    action_office     LIKE 'E%'
    

    Instead?

  • How to return two values of a function?

    Hi all
    I have a function which returns a varchar2 value. This value is used in the SQL of a ref cursor

    Now I want this function returns two values. I tried to use varray, but could not accomplish the task.

    Can you tell me how can I find the two values from a function? and how this function can be called in a SQL query?

    Thank you very much

    The query should look like:

    SELECT v.col.name AS name
         , v.col.flag AS flag
    FROM   ( SELECT kk_test_kk(t.somecolumn,t.someothercolumn,42) AS col
             FROM   sometable t ) v;
    

    Note that you need to prefix with the name of view inline ('v' in the example) and the expression of the function ('col' in the example).

  • Form libraries: package with function returning collections?

    Hello

    I have a form library that I created a package to manage a collection

    in this package, I can add to my collection

    but I would like to have another function to return my collection, how is this possible?

    For now, I tried something like this:

    In my BODY of PACKAGE

    TYPE tvItem is table of varchar2(100) index by pls_integer;
     mycollectiontvItem;
     
    function getCollection return tvItem is
      begin
      
        return mycollectiontvItem;
    
      end;
    
    

    and in my STATEMENT of PACKAGE

    function getCollection return tvItem;
    
    

    but the tvItem structure is not declared.  is it possible to return the collection?

    Thanks for your help.

    Sam wrote:

    but the tvItem structure is not declared.  is it possible to return the collection?

    You get the error, "tvItem structure is not declared" because it is just the definition of the type of data - not an instance of the data type.  When you use user-defined types, you must create an instance of the type in order to to use as a type in your function.  You must instead use "MyCollection" in return.  In addition to that my just be a typo, but your statement of 'MyCollectiontvItem' should be 'MyCollection tvItem structure.

    Craig...

  • catch the collection returned by the function in a SQL statement

    I have a select like query: (I need all the values returned by the function in the select list)

    Select t1.col1, t2.col2, (by selecting t.a, t.b., t.c in fn (t2.col3) t)
    Of
    T1, t2
    where t1.col1 = t2.col2;



    My function is like:

    FN (T2.col3) returns an array in format of the object



    Here, I was able to select only one value from the table returned by the funcation both. If I select all of the values as above, she gave too much error vales.
    Please someone help me in this

    user13044793 wrote:
    I have a select like query: (I need all the values returned by the function in the select list)

    Select t1.col1, t2.col2, (by selecting t.a, t.b., t.c in fn (t2.col3) t)
    Of
    T1, t2
    where t1.col1 = t2.col2;

    No specific reason for this? It adds additional complexity to the projection of SQL, and there are additional costs of failover for the motor of PL/SQL (per line) of context. Overall - not your typical approach and one that should have sound justification.

    With regard to the basic method - the SQL multiset() function should be used to create a collection. Here is an example of the approach:

    SQL> create or replace type TFoo as object(
      2          id      number,
      3          bar     varchar2(5)
      4  );
      5  /
    
    Type created.
    
    SQL>
    SQL> create or replace type TFooSet as table of TFoo;
      2  /
    
    Type created.
    
    SQL>
    SQL> create or replace function GetSomeFoo( n number ) return TFooSet is
      2          foo     TFooSet;
      3  begin
      4          foo := new TFooSet();
      5          foo.Extend( 5 );
      6
      7          for i in 1..5
      8          loop
      9                  foo(i) := new TFoo( n+i-1, to_char(i-1,'0000') );
     10          end loop;
     11
     12          return( foo );
     13  end;
     14  /
    
    Function created.
    
    SQL>
    SQL> select
      2          object_id,
      3          object_name,
      4          cast(
      5                  multiset( select * from table(GetSomeFoo(object_id)) ) as TFooSet
      6          )       as FOO
      7  from       all_objects
      8  where      owner = 'SYS'
      9  and        rownum <= 5;
    
     OBJECT_ID OBJECT_NAME                    FOO(ID, BAR)
    ---------- ------------------------------ --------------------------------------------------
         27538 /1000e8d1_LinkedHashMapValueIt TFOOSET(TFOO(27538, ' 0000'), TFOO(27539, ' 0001')
                                              , TFOO(27540, ' 0002'), TFOO(27541, ' 0003'), TFOO
                                              (27542, ' 0004'))
    
         28544 /1005bd30_LnkdConstant         TFOOSET(TFOO(28544, ' 0000'), TFOO(28545, ' 0001')
                                              , TFOO(28546, ' 0002'), TFOO(28547, ' 0003'), TFOO
                                              (28548, ' 0004'))
    
         11718 /10076b23_OraCustomDatumClosur TFOOSET(TFOO(11718, ' 0000'), TFOO(11719, ' 0001')
                                              , TFOO(11720, ' 0002'), TFOO(11721, ' 0003'), TFOO
                                              (11722, ' 0004'))
    
         30094 /100c1606_StandardMidiFileRead TFOOSET(TFOO(30094, ' 0000'), TFOO(30095, ' 0001')
                                              , TFOO(30096, ' 0002'), TFOO(30097, ' 0003'), TFOO
                                              (30098, ' 0004'))
    
        684122 /1023e902_OraCharsetUTFE       TFOOSET(TFOO(684122, ' 0000'), TFOO(684123, ' 0001
                                              '), TFOO(684124, ' 0002'), TFOO(684125, ' 0003'),
                                              TFOO(684126, ' 0004'))
    
    SQL>
    SQL> with dataset as(
      2          select
      3                  object_id,
      4                  object_name,
      5                  cast(
      6                          multiset( select * from table(GetSomeFoo(object_id)) ) as TFooSet
      7                  )                as FOO
      8          from    all_objects
      9          where   owner = 'SYS'
     10          and     rownum <= 5
     11  )
     12  select
     13          d.object_id,
     14          d.object_name,
     15          f.id,
     16          f.bar
     17  from   dataset d,
     18          table(d.foo) f
     19  /
    
     OBJECT_ID OBJECT_NAME                            ID BAR
    ---------- ------------------------------ ---------- ---------------
           217 DUAL                                  217  0000
           217 DUAL                                  218  0001
           217 DUAL                                  219  0002
           217 DUAL                                  220  0003
           217 DUAL                                  221  0004
           268 SYSTEM_PRIVILEGE_MAP                  268  0000
           268 SYSTEM_PRIVILEGE_MAP                  269  0001
           268 SYSTEM_PRIVILEGE_MAP                  270  0002
           268 SYSTEM_PRIVILEGE_MAP                  271  0003
           268 SYSTEM_PRIVILEGE_MAP                  272  0004
           271 TABLE_PRIVILEGE_MAP                   271  0000
           271 TABLE_PRIVILEGE_MAP                   272  0001
           271 TABLE_PRIVILEGE_MAP                   273  0002
           271 TABLE_PRIVILEGE_MAP                   274  0003
           271 TABLE_PRIVILEGE_MAP                   275  0004
           274 STMT_AUDIT_OPTION_MAP                 274  0000
           274 STMT_AUDIT_OPTION_MAP                 275  0001
           274 STMT_AUDIT_OPTION_MAP                 276  0002
           274 STMT_AUDIT_OPTION_MAP                 277  0003
           274 STMT_AUDIT_OPTION_MAP                 278  0004
           815 RE$NV_LIST                            815  0000
           815 RE$NV_LIST                            816  0001
           815 RE$NV_LIST                            817  0002
           815 RE$NV_LIST                            818  0003
           815 RE$NV_LIST                            819  0004
    
    25 rows selected.
    
    SQL>
    

Maybe you are looking for

  • How can I get software, drivers for a 20 inch HP W2081d monitor for my MacMini

    Mac Mini (mid-2010) 2.4 Ghz OS - X El Capitan 10.11.3 Version Trying to find Mac software, drivers for HP 20 inch W2801d. HP provides software for Windows machines only, but refers to the update of the Apple software. Please let know us the problem..

  • Satellite A200 starts

    Hello I had Satellite A200 given to me will not post.Long warranty, but what I like to know what error or light mean because he try to post. I get two 2 blue lights on it, power and ms in. If remove the ram I get no beeps or anything.If do USB floppy

  • Satellite A30 external monitor

    HalloI used an LG Flatron L1910B 19 "external monitor for the past 2 years without any problem using the combo Intel Extreme Graphics Hotkey of Ctrl Alt F3 to switch. I had to swapout 1910B who had died with a LG L1917S monitor. Now I can't access my

  • Phones of motorcycle and cars toyota

    well, I've been holding off the coast on this cause, that I was hoping the upgrade to lollipop would fix this, but we are still waiting for lollipop and who knows when it comes out. OK so I bought the turbo the day it was released in October, next mo

  • Dexcom G4 Glucose monitor

    DexCom progran G4 Dexcom Studio 12.0.3.43 will not download my monitor data