Collection as a parameter in the function - help needed

I have a function that returns 3 different values according to a given in parameter.
Now, I want to return these three values.
Instead of using three out parameters, how can I use a collection for return values.

Please tell me the best way that returning multiple values (more than 3)

Thanks in advance

Concerning
Rambeau
SQL> create type my_obj as object (no integer, name varchar2(10))
  2  /

Type created.

SQL> create type my_tbl as table of my_obj
  2  /

Type created.

functional approach...

SQL> create or replace function my_fn return my_tbl
  2  as
  3     ltbl my_tbl;
  4  begin
  5     select my_obj(1,'karthick') bulk collect into ltbl from dual;
  6
  7     return ltbl;
  8  end;
  9  /

Function created.

SQL> select * from table(cast(my_fn() as my_tbl))
  2  /

        NO NAME
---------- ----------
         1 karthick

procedureal approach...

SQL> create or replace procedure my_proc(ptbl out my_tbl)
  2  as
  3  begin
  4     select my_obj(1,'karthick') bulk collect into ptbl from dual;
  5  end;
  6  /

Procedure created.

SQL> declare
  2     ltbl my_tbl;
  3  begin
  4     my_proc(ltbl);
  5
  6     for i in 1..ltbl.count
  7     loop
  8             dbms_output.put_line(ltbl(i).no||'      '||ltbl(i).name);
  9     end loop;
 10  end;
 11  /
1       karthick

PL/SQL procedure successfully completed.

Tags: Database

Similar Questions

  • How to pass parameter in the function using the select statement?

    Hello

    I had a problem. I can't pass as parameter to the function by using the select statement. But it can pass as a parameter using the "code". How can I solve this problem?

    For example,.
    Select * from table (SplitFunction ('HS750020, HS750021')) < < < this work.

    but

    Select * from table (SplitFunction (select LOT_NO in the TRACER_SEARCH_SCHEDULE where JOB_ID = '36')) < < < do not work.

    Thank you for trying to help him. Thank you.

    Select * from table (SplitFunction (select LOT_NO in the TRACER_SEARCH_SCHEDULE where JOB_ID = '36'))< do="" not="">

    Try like this

    select * from table(select splitfunction(lot_no) from tracer_search_schedule where job_id='36')
    

    Just make sure that your subquery returns only 1 row.

  • How to pass parameter in the function extract (for XMLTYPE)

    I have a table with XMLTYPE field xml_column PROBLEMXML. In this column, there are many deffinitions for the problem. There is no amount deffinitions max and there can be no definition at all. I need to return all the definitions of all the problems a string wirh separate definitions by '; '.

    Query
    SELECT extract (prob. Def,'/definitions/definition[1]/@var'). ';'|| excerpt (prob. Def,'/definitions/definition[2]/@var')
    OF PROBLEMXML j.
    XMLTABLE)
    "/ problem.
    PASSAGE j.xml_column
    Probid VARCHAR COLUMNS (31) PATH ' / problem/@id',
    Prob def XMLTYPE PATH ' / problem/definitions ")
    where PROBLEM_ID = 1;
    Returns exactly what I want one; m.
    But
    declare
    my_variable varchar2 (2000): = null;
    number of N1;
    number of N2;
    Start
    N1: = 1;
    N2: = 2;
    SELECT extract (prob. Def,'/definitions/definition[N1]/@var'). '|'|| excerpt (prob. Def,'/definitions/definition[N2]/@var') in my_variable
    OF ETL_PROBLEMXML_STG_T j.
    XMLTABLE)
    "/ problem.
    PASSAGE j.xml_column
    Probid VARCHAR COLUMNS (31) PATH ' / problem/@id',
    Prob def XMLTYPE PATH ' / problem/definitions ")
    where PROBLEM_ID = 1;
    dbms_output.put_line ($my_var);
    end;
    Returns null.
    Is there a way to switch the setting to extract the function?

    You have string literal death of n1 and n2. Note the change to select it.

    DECLARE
      my_var VARCHAR2(2000) := NULL;
      n1     NUMBER;
      n2     NUMBER;
    BEGIN
      n1 := 1;
      n2 := 2;
      SELECT extract(prob.def, '/Definitions/Definition[' || n1 || ']/@var') || '|' ||
             extract(prob.def, '/Definitions/Definition[' || n2 || ']/@var')
        INTO my_var
        FROM etl_problemxml_stg_t j,
             xmltable('/problem' passing j.xml_column columns probid VARCHAR(31) path '/problem/@id',
                      def xmltype path '/problem/Definitions') prob
       WHERE problem_id = 1;
      dbms_output.put_line(my_var);
    END;
    

    Published by: RPuttagunta on December 13, 2010 09:18

  • is there a way to collect images used similar to the function "package for output?

    I would like to collect only the images/assets I use per page in Dreamweaver. Is there a function that automates that?

    There are browser add-ons that can help you with it like this for FF.

    DownThemAll! : Modules for Firefox

    Nancy O.

  • Pass the parameter to the functions called from a dll

    Hi all

    I am interfacing a motor controller for PMC - 100 through the Protocol of Performax using labwindows.

    I need to explicitly link the PerformaxCom.dll and call functions with him. I'm calling this function

    BOOL fnPerformaxComOpen (DWORD IN dwDeviceNum, OUT HANDLE * pHandle);

    Faithful:

    If you want to link explicitly, you can consult this article: http://zone.ni.com/devzone/cda/tut/p/id/8503

    It has a code snippet that shows passing two parameters to a DLL function.

    But as for your statement that "I don't know how to pass parameter to him", in the example, you reference, you pass a parameter: it's just a constant string rather than a variable.

  • not able to pass the table name as parameter in the function

    Hello

    I am not able to move from tablename as parameter. I use the below function.
    -------------------------------------------------------------------------------------------------

    function count_test (tabname varchar2) return number is
    l_count number;
    Start

    Select count (*) IN the tabname FROM l_count;

    RETURN l_count;
    END;

    You can not do with static SQL.

    The only way is to do it with dynamic SQL:

    EXECUTE IMMEDIATE ' select count (*) FROM ' | tabname INTO l_count;

    Kind regards.
    Al

    Published by: Alberto Faenza 10 may 2012 01:44
    Misspelling

  • Cursor to pass as a parameter in the function Operator Table

    Hello

    I have a Table function operator which accepts a single parameter (SYS_REFCURSOR). How can I pass Table as a cursor to the Table function?

    Thank you.
    -bzx

    Hello

    You use an operator of CONSTRUCTION to build a SYS_REFCURSOR, entries are the columns of your representative request for the ref cursor operators and the output type is an attribute of SYS_REFCURSOR. This can then be mapped to your entry table function.

    See you soon
    David

  • Strange behavior with the function «Help in command line»

    So I do a little playing with the opening of the files compiled help (.chm) with the command-line help feature, and I saw a strange behavior when trying to index multi-level access keywords. According to the documentation, if you set the 'Key' operation, you can enter a value for ' string to search for "to access this section. The more precise help that:

    If this string contains a keyword index, the string must match the key of the index as it appears in the help index file. To access a topic with a multilevel index keyword, enter the keyword of the top-level index, a colon and the keyword of the second level index. Do not separate the elements with spaces. For example, a chain of error codes: GPIB jumps about a subject with a keyword of top-level index of error codes and a second level keyword index of GPIB.

    All right, seems simple enough. Except that when I tried, I couldn't work, even with the example provided. I tried the following simple test:

    Opens the help file, but it opens to this page, not to the page ' error codes: GPIB "non-descript. I saw this in 8.2 and 8.6. Anyone have any success with access to a multi-level keyword?

    Note - side

    Curiously, the Index for the help lvconcepts.chm file looks like this:

    In other words, the input index text is just "GPIB", but the text that appears in the keyword field is "codes error, GPIB. I'm curious to know how this was accomplished. I decompiled the lvconcepts.chm file and watched the .hhk file, and it is not immediately obvious to me. (By the way, if you try to use "error codes, GPIB" it does not either).

    Hello

    Please contact National Instruments!
    It is a very strange behavior.  I tested out and seen the exact
    same results you are experiencing.  This was reported to R & D (AUTO ID # 130246) for further investigations.
    From what I can tell the a possible workaround solution that we have documented
    in the post of root Canal.  I can't continue to look into this in order
    to see if there is no other workaround solution or a reason why it is
    run in this way.  Thanks much for the feedback!  If
    you have any other questions on this subject please post them here.
    Have a great day!

  • Passing parameter to the function header javascript problem

    Hi - I'm trying to pass a string to a javascript function. The javascript function is called an onchange
    event in the attributes of a page element HTML form elements. The call looks like this:

    OnChange = 'lookupObjTypeID ("P3_OBJECTTYPE_NAME")'; (Yes, I want to pass the name of the element, not its value)

    The JavaScript looks like this:

    < script LANGUAGE = "JavaScript" src = "http://www.json.org/json.js" > < / script >
    < script type = "text/javascript" >

    function lookupObjTypeID (source_item_name) {}

    Alert ("running javascript");
    Alert (' name of the Source element: ' | source_item_name);
    }
    < /script >

    The first alert prints the message; the second alert but the source_item_name is null.

    Everything I've seen, this is the right syntax. What's not?

    Thank you
    Carol

    Carol

    Is the in js concatenation operator ' + '. Then

    Alert (' name of the Source element: "+ source_item_name);

    should work.

    CITY

  • Pass the parameter to the function onRelease

    Hello

    Is it possible to pass parameters to mc.onRelease?

    Thank you

    aobs

    No, but is not necessary.  You can assign properties to your movieclip and get back them in your onRelease:

    mc.clickedNum = 0;

    {mc.onRelease = function ()}

    this.clickedNum ++;

    }

  • Duplicate the data in the fields Help Needed

    We have a 9 Word form page which has a few repeat information, have converted to LiveCycle but am stuck on knowledge how to make the data in a field show also in another so that the user doesn't have to enter twice.  Finally, we will remove the duplicated fields, but for many reasons, at the moment they must stay there.  I don't want a contractor having to enter their name twice, etc. and have my main form of data on the front of the 9 pages, and then when they get to the last page with sigs, etc., I would that they have already entered for their company information to show.

    I am very new to Designer ES, and when I did some forms in Adobe 9.0 forms some time back, all I had to do was of the same name and if I entered info in one he would show to another.  ARE does not seem to do that, and I can't find out how to add any code to the field.  Don't know why, but a lot of my options are grayed out.

    In any case, would be very grateful help, thank you.

    Giving them the same name is only part of the solution... .you need to change the link (on the object palette/link tab) to Global.

    Paul

  • position of the cell - help needed, please

    I have problems with this site, that is created with a table.

    It displays perfectly in Safari (on Mac), but it is messed up in Firefox (PC and Mac) and Internet Explorer (PC). The problem is that the cell containing the navigation (to the top left, under the logo) moves from page to page and goes on some pages.

    This cell is supposed to appear right under the logo with just a small margin of the background showing through. Here's what's happening really (on a sample of pages):
    in the news - good, as well as contact and what you can do
    buy pine - too low and too long (too much space under the last link)
    Merchant Navy - far too low and too long
    what is everything - waaaay too low and waaaay too long (the worst of pages)

    Tests, I found that the question seems to be content in the right cell (the cell of great content on the right area), rather than the navigation or logo cell left. But I can't understand exactly what causes problems of size/position or how to fix it.

    I would appreciate any suggestions. Thank you!

    Alignments of cells can be tricky, when you merged cells like this. I think that the best way to solve this problem is to place all the elements (logo and navigation) left in a nested table, within a single merged cell on the left, which only moves based on the content on the right.

    Andy

  • How to pass the value entered for the parameter IN a function

    Hello
    I'm new to pl/sql programming.
    The function below is used inside a package and the package is called in visual studio.
    The function uses the input parameters 2.
    Out what "in_report_parameter_id" value comes through the application of service job processor.
    The second IN the parameter values are hard coded into the function.
    I am not able to understand this.
    If the values are hard coded, how to ensure that only the hard coded values are the right ones?
    Please could someone explain?
    I don't really have good idea on how to move the INPUT parameter to the function or procedure
    Is there any nice document that could give me good understanding about what are the ways or types we could transmit values to the input in the subprogrammes parameter?

    Thanks in advance.

    CREATE OR REPLACE FUNCTION get_class_text_str
    (
         in_report_parameter_id IN NUMBER,
         in_which                IN VARCHAR2 DEFAULT 'SELECT'
    )
    RETURN VARCHAR2
    IS
             end_text            VARCHAR2 (50)   := ''; 
             my_class_text_str  VARCHAR2(10000) := '';
             my_class_value_str VARCHAR2(10000) := '';
     
         CURSOR class_text(c_1_text VARCHAR2, c_2_text VARCHAR2) IS
         SELECT c_1_text || report_parameters.report_parameter_value 
                               || c_2_text
                               || report_parameters.report_parameter_value 
                               || '" '
          FROM report_parameters
         WHERE report_parameters.report_parameter_id     = 3690
           AND report_parameters.report_parameter_group  = 'CLASS'
           AND report_parameters.report_parameter_name   = 'CLASS'
     GROUP BY report_parameters.report_parameter_value
     ORDER BY CAST(report_parameters.report_parameter_value AS NUMBER);
     
    BEGIN
    
         IF (in_which = 'SUM') THEN     
      
              OPEN class_text ( 'SUM(NVL("Class ', '", 0)) "Class ' );
        
         ELSIF (in_which = 'PERC')THEN
      
              OPEN class_text ( 'ROUND((("Class ', '" / "Total") * 100), 2) "Class ' );
              end_text := ', DECODE("Total", -1, 0, 100) "Total" ';
        
         ELSE
      
              OPEN class_text ( 'SUM(DECODE(bin_id, ', ', bin_value, 0)) "Class ' );
        
         END IF;
     
         LOOP
              FETCH class_text INTO my_class_value_str;
              EXIT WHEN class_text%NOTFOUND;
     
              my_class_text_str := my_class_text_str || ', ' || my_class_value_str;
         END LOOP;
     
         CLOSE class_text;
      
         my_class_text_str := my_class_text_str || end_text;
     
         RETURN my_class_text_str;
         
    END get_class_text_str;
    /
    Published by: user10641405 on November 19, 2009 08:16

    Published by: user10641405 on November 19, 2009 08:30

    This is not a conception I would use, but should work if coded correctly. I would probably create a reference text cursor query and use a fetch of open and close.

    You have 2 input parameters, in_report_parameter_id and in_which. I could not find where in_report_parameter_id has been used in the program, but the value passed to in_which is used in the logic of the FI to decide on opening the cursor. After the cursor is opened lines are to be read and possibly the cursor is closed.

    The in_which values are compared to the are hard-coded. It is the programming interface to ensure that the values are the values and the measures taken are also correct. Your program is assuming that if the first 2 values are not met the third listed is the one you want.

    To pass values of entry in a procedure you simply provide the values as a literal or something like variable in the call,

    whatever := get_class_text_str(1,'SELECT');
    
  • 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>
    
  • Need help with the function

    First off the coast to let put me the warning that I am not the right Wick informed in PL/SQL. I use this for an example posted in the forum of the APEX.

    I need the function to return values based on the user role. I know, it's probably the ugliest pl/sql, you may have seen yet ;) I hope that you guys can decipher the logic that I use. Obviously, this code does not validate.

    You guys could help me with this?

    FUNCTION to CREATE or REPLACE return_art_lov_fn
    RETURN art_table_type
    AS
    v_data art_table_type: = art_table_type ();
    BEGIN
    IF
    EXISTS (SELECT ' 1' FROM GBL_PEOPLE, GBL_ACCESS WHERE upper (gbl_people.userid) = upper (app_user) AND gbl_people.person_id = gbl_access.person_id and gbl_access.art_role = 9)
    THEN
    FOR c IN (SELECT reverse_name, person_id
    OF gbl_people)
    LOOP
    v_data. EXTEND;
    v_data (v_data. (COUNTY): = art_rectype (c.person_id, c.reverse_name);
    END LOOP;
    ON THE OTHER
    FOR c IN (select reverse_name, person_id of GBL_PEOPLE where upper (userid) = upper (APP_USER) and current_flag is not null
    Union
    Select reverse_name, person_id from GBL_PEOPLE where mgr_person_id = (select person_id in GBL_PEOPLE where upper (userid) = upper (APP_USER) and)
    (current_flag is not null) and current_flag is not null)
    LOOP
    v_data. EXTEND;
    v_data (v_data. (COUNTY): = art_rectype (c.person_id, c.reverse_name);
    END LOOP;
    ENDIF;
    RETURN v_data;
    END;

    -Vinod

    My guess is that you want something like

    CREATE OR REPLACE FUNCTION return_art_lov_fn
      RETURN art_table_type
    AS
      v_data art_table_type;
      l_cnt    integer;
    BEGIN
      SELECT 1
        INTO l_cnt
        FROM dual
       WHERE EXISTS(
          SELECT 1
            FROM gbl_people p,
                 gbl_access a
           WHERE upper( p.userid ) = upper( app_user )
             AND p.person_id       = a.person_id
             AND a.art_role        = 9
       );
    
      IF( l_cnt = 1 )
      THEN
        SELECT art_rectype( person_id, reverse_name )
          BULK COLLECT INTO v_data
          FROM gbl_people;
      ELSE
        SELECT art_rectype( person_id, reverse_name )
          BULK COLLECT INTO v_data
          FROM (SELECT person_id, reverse_name
                  FROM gbl_people
                 WHERE upper(userid) = upper(app_user)
                   AND current_flag is not null
                UNION
                SELECT person_id, reverse_name
                  FROM gbl_people
                 WHERE mgr_person_id = (SELECT person_id
                                          FROM gbl_people
                                         WHERE upper(userid) = upper( app_user )
                                           AND current_flag is not null)
                   AND current_flag is not null);
      END IF;
    
      RETURN v_data;
    END;
    

    If this does not work (I do not have definitions table, so I can't try to compile it myself), please report all errors of compilation (including line numbers).

    Justin

Maybe you are looking for

  • DeskJet F4140: Deskjet F4140 stopped working after paper jam

    I had a paper jam. Folowwing HP statement, I removed the back and get rid of the jam. New, everything is clear. The printer lights up as he wants to work, but will not go through the print operation. Thank you

  • Boot from SSD

    Hello to all members I had a new E15 D 571 G 735 that comes with a 1 TB hard drive, I have a SDS 120 GB I want to use for the OS, put it on the DVD slot (which incidentally is empty). The question here is how to do, because from my point of view of t

  • info on screen is sideways, how can I solve this

    all the info on screen are on the side - what I've done and how to fix thks

  • My laptop is * USELESS *.

    Then, I had originally Windows Vista on my laptop that comes with it. Some time ago I have upgraded to Windows 7... I used a MSDN key, now I can't use this key, it turned out to be non-genuine, I decided to use Rescue and Recovery to restore my syste

  • Q10 guest - zone problem blackBerry calendar event

    Hi all! I've just switched back to BlackBerry, iPhone and love everything about it so far except for one thing: calls on the calendar time zone problems. My work using an OS X hosted the CalDAV server, and I was able to sync my existing calendars to