Functions returning records

I have a function that returns a record, a row type from a table I selected
In a procedure I now try to call values from this function by calling
function.value1
however I get the error
subprogram or cursor 'function' reference is out of scope
does anyone know what is wrong?
thanks

I can only provide some pattern
-- your function:
create or replace function your_function(p_param(s) in data_type) return your_table%rowtype is
  return_value your_table%rowtype;
begin
  < your processing here (return_value gets a value assigned) >
  return return_value;
end;
-- your procedure:
create or replace procedure your_procedure(p_param(s) in data_type) is
  function_value your_table%rowtype;
  some_variable data_type;
begin
  < your processing here >
  function_value := your_function(p_param(s));
  some_variable := function_value.rowtype_column_name;
end;Regards
Etbin

Similar Messages

  • Can stored function return record type or cursor type?

    Hi everybody,
    I am working with a stored function now.
    Can the function output more that ONE result? i.e. cursor or record type.
    Thanks.
    Brigitta.

    Brigitta,
    If you are calling the stored function from SQL then the function can only return one of the base datatypes, as Murali has said. However, if you are calling the function from PLSQL you can return any complex datatype, eg:
    package test_package is
    type rec_test is
      ( col_a number
      , col b varchar2(30) );
    type tab_test is
      table of rec_test
      index by binary ineteger;
    function test_function (.....)
    return tab_test;
    end test_package;and to call this function:
    declare
    l_table test_package.tab_test;
    begin
    l_table := test_package.test_function(....);
    end;Hope that helps!

  • Function return single record

    create or replace function etest
    (dep in number)
    return varchar2
    is
    dept number:= 0;
    cursor c1 is
    select deptno
    into dept
    from emp
    where deptno = dep;
    begin
    open c1;
    loop
    fetch c1 into dept;
    exit when c1%notfound;
    end loop;
    close c1;
    return dept;
    end;
    Dear all
    the above function return only one return ,,,but i want to display all record that belong to department 10
    it just i idea that what i want to do....!
    and Secondly
    how i fetch multiple column like i enter department 10 and it give output like
    empno ename sal
    7782 CLARK 2450
    7739 KING 5000
    7934 MILLER 13000
    Thanks to all

    You could use a REF CURSOR:
    PL/SQL 101 : Understanding Ref Cursors
    http://www.oracle-base.com/articles/misc/UsingRefCursorsToReturnRecordsets.php
    or maybe a pipelined function....
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:19481671347143
    http://www.oracle-base.com/articles/9i/PipelinedTableFunctions9i.php
    depending on what client is fetching.

  • Custom function to return Record Selection Criteria

    <p>Here&#39;s what I need to do. There will be two prompts for range of dates; say, Begin date and End Date on almost all of the reports here. But it is not mandatory to enter Begin Date nor end date. So depending on the data the user enters we have to build the where clause.</p><p>So, to achive this I am trying to write a custom function which accepts the column name , and data from the parameters in the report. </p><p>my_func(col_nme, bgn_date, end_date) .. </p><p>This function does all the validations and returns a string depending on the data entered by the user. </p><p> Eg., if user entered only begin date then it will return col_nme <= bgn_date<br />      if user entered both dates then col_nme between bgn_date and end_date</p><p> And I am trying to user this complete clause in my record selection of the report. </p><p>In Record Selection call my_func({Query.Eff_date},p_bgn_date,p_end_date) </p><p>It is not accepting it since the function returns it as a string and the Reord selection should return a bolean. </p><p>Can any one let me know how to get this functionality in my report. </p><p>&#160;</p><p>ANy other suggestions to achieve this would be a great help<br />Thanks a lot in advance. </p>

    as long as you have discrete and multi values checked on for the parameter, the resulting array is all you need.
    In the RSF, the desired results will be returned by a REALLY simple boolean statement
    {table.field} in {?my param}
    "Like" may replace "in"Â for some cases.
    Try it, you'll like it. :)Â
         - Kathryn Webster (Report Design Consultant)
               Kat&#39;s News: http://diamond.businessobjects.com/blog/279

  • Oracle 11g Table function returns no records on first call

    Hello,
    On a Oracle 11g R2 I've a table function ( PIPELINED ) returning rows selected from a table.
    The first time the function is selected, in a session ( I've tried to disconnect and log in again ), it returns no rows.
    I've tried to log the call using DBMS_OUTPUT and from what I see the select on the table function returns no rows and no output is printed. So I presume Oracle is not calling the function.
    The same function on a similar environment ( same db versions, patches and database structure ) works fine. The second environment is a production environment so it has more memory and some other settings enabled.
    Does anyone know of settings that can relate to this behaviour ?
    Thanks in advance for the help.
    Regards,
    Stefano Muret

    Thank you for answering so fast.
    Here's the function code:
    FUNCTION template_parameters (iTemplate IN TEMPLATE_RAW_DATA.TMPL_ID%TYPE := NULL)
    RETURN table_type_tmpl_parameters PIPELINED
    IS
    li_exception INTEGER DEFAULT -20025;
    POUT_PARM TABLE_TYPE_TMPL_PARAMETERS;
    lt_parms table_type_tmpl_parms_raw;
    sParmCheck VARCHAR2(4000);
    iOccurrence INTEGER;
    BEGIN
    pOut_Parm := table_type_tmpl_parameters();
    pOut_Parm.EXTEND;
    select
    tmpl_id
    *,tmpl_name*
    *,replace(upper(trim(sql_out)),'[SCHEMA].')*
    *,UPPER(TRIM(out_tmpl_parms))*
    bulk collect into lt_parms
    from ref_templates
    where tmpl_id = NVL(iTemplate,tmpl_id)
    order by tmpl_id;
    FOR k IN 1..lt_parms.COUNT
    LOOP
    pOut_Parm(1).tmpl_id := lt_parms(k).tmpl_id;
    pOut_Parm(1).tmpl_name := lt_parms(k).tmpl_name;
    FOR i IN 1..2
    LOOP
    IF i = 1 THEN
    sParmCheck := lt_parms(k).sql_out;
    ELSE
    sParmCheck := lt_parms(k).sql_parms;
    END IF;
    iOccurrence := 1;
    *pOut_Parm(1).parameter_name := regexp_substr(sParmCheck,'\[[^\[]+\]',1,iOccurrence);*
    WHILE pOut_Parm(1).parameter_name IS NOT NULL
    LOOP
    PIPE ROW (pOut_Parm(1));
    iOccurrence := iOccurrence + 1;
    *pOut_Parm(1).parameter_name := regexp_substr(sParmCheck,'\[[^\[]+\]',1,iOccurrence);*
    END LOOP;
    END LOOP;
    END LOOP;
    RETURN;
    EXCEPTION
    WHEN OTHERS THEN
    RAISE_APPLICATION_ERROR(li_exception,SUBSTR(SQLERRM,1,1000));
    RETURN;
    END template_parameters;
    This function is part of a package.
    The data on both environments is the same.

  • Return records from Stored Procedure to Callable Statement

    Hi All,
    I am createing a web application to display a students score card.
    I have written a stored procedure in oracle that accepts the student roll number as input and returns a set of records as output containing the students scoring back to the JSP page where it has to be put into a table format.
    how do i register the output type of "records" from the stored function in oracle in the "registerOutParameter" method of the "callable" statement in the JSP page.
    if not by this way is there any method using which a "stored function/procedure" returning "record(s)" to the jsp page called using "callable" statement be retrieved to be used in the page. let me know any method other that writing a query for the database in the JSP page itself.

    I have a question for you:
    If the stored procedure is doing nothing more than generating a set of results why are you even using one?
    You could create a view or write a simple query like you mentioned.
    If you're intent on going the stored procedure route, then I have a suggestion. Part of the JDBC 2.0 spec allows you to basically return an object from a CallableStatement. Its a little involved but can be done. An article that I ran across a while back really helped me to figure out how to do this. There URL to it is as follows:
    http://www.fawcette.com/archives/premier/mgznarch/javapro/2000/03mar00/bs0003/bs0003.asp
    Pay close attention to the last section of the article: Persistence of Structured Types.
    Here's some important snippets of code:
    String UDT_NAME = "SCHEMA_NAME.PRODUCT_TYPE_OBJ";
    cstmt.setLong(1, value1);
    cstmt.setLong(2, value2);
    cstmt.setLong(3, value3);
    // By updating the type map in the connection object
    // the Driver will be able to convert the array being returned
    // into an array of LikeProductsInfo[] objects.
    java.util.Map map = cstmt.getConnection().getTypeMap();
    map.put(UDT_NAME, ProductTypeObject.class);
    super.cstmt.registerOutParameter(4, java.sql.Types.STRUCT, UDT_NAME);
    * This is the class that is being mapped to the oracle object. 
    * There are two methods in the SQLData interface.
    public class ProductTypeObject implements java.sql.SQLData, java.io.Serializable
        * Implementation of method declared in the SQLData interface.  This method
        * is called by the JDBC driver when mapping the UDT, SCHEMA_NAME.Product_Type_Obj,
        * to this class.
        * The object being returned contains a slew of objects defined as tables,
        * these are retrieved as java.sql.Array objects.
         public void readSQL(SQLInput stream, String typeName) throws SQLException
            String[] value1 = (String[])stream.readArray().getArray();
            String[] value2 = (String[])stream.readArray().getArray();
         public void writeSQL(SQLOutput stream) throws SQLException
    }You'll also need to create Oracles Object. The specification for mine follows:
    TYPE Detail_Type IS TABLE OF VARCHAR2(1024);
    TYPE Product_Type_Obj AS OBJECT (
      value1  Detail_Type,
      value2 Detail_Type,
      value3 Detail_Type,
      value4 Detail_Type,
      value5 Detail_Type,
      value6 Detail_Type,
      value7 Detail_Type,
      value8 Detail_Type);Hope this helps,
    Zac

  • Report- Pl/sql function returning sql query parsing page items as text?

    Hi Team,
    I am facing a strange issue .
    I have four page items namely
    1)JOB_CODE
    2)MIN_EXP
    3) MAX_EXP
    4) SOURCES1
    I have a report of the type "Pl/sql function returning sql query"
    declare
    v_sql varchar2(4000);
    begin
    if (:JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql:= 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:JOB_CODE IS NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MIN_EXP IS NULL and :JOB_CODE IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years <= :MAX_EXP and V_REQUIREMENT = :JOB_CODE and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MAX_EXP is null and :JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    end if;
    insert into query_list values (v_sql);
    insert into debug values (:JOB_CODE , :MIN_EXP , :MAX_EXP , :SOURCES1);
    return v_sql;
    end;
    Please not that I am insertin the query into a table called Query_list and the page item values into the table called Debug thru the pl/sql function which returns teh query.
    Now I select the data from the debug tables.
    select unique(query) from query_list;
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like '%:SOURCES1%'
    select * from debug;
    JOBCODE     MINEX     MAXEX     SOURCE
    21     1     10     donkeyHire
    And if I run the query in sql I get some records returned
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = 21 and v_experience_years >= 1 and v_experience_years <= and source like 'donkeyHire'
    V_CANDIDATE_ID     V_FNAME     V_CURRENT_EMPLOYER     V_EXPERIENCE_YEARS
    2     Vengu     Andale Tech     4
    But the record does not show up in the report!
    does this type of report parse page items as text?
    Why is it so?
    Waiting for an early reply.
    Thanks,
    venkat

    Venkat - You don't want to put ':SOURCES1' in quotes like that.
    Scott

  • Function return value == -10. Native error code -2146824584 ADOBD.Recordset: Operation is not allowed when object is closed

    I want to call Stored Procedure that return records and output parameter, from CVI
    I can get output parrameter but when I want to get records stream I recieve following wrror:
    function return value == -10. Native error code -2146824584 ADOBD.Recordset: Operation is not allowed when object is closed

    in Stored procedure I create table variable and and insert into string values
    when I remove usage of table variable the error desappear

  • On Submit process not firing -report (PL/SQL function returning SQL query)

    Can anyone suggest possible causes / solutions for the following problem?
    I have a report region that uses a PL/SQL function returning SQL query. The report allows the user to update multiple fields / rows and then click a button to submit the page which should run the On-Submit process to update the database. However the process does not run and I get a 'HTTP404 page cannot be found' error; and when I navigate back using the Back button I cannot then navigate to any other page in my application without getting the same error. The button was created by a wizard selecting the options to submit the page and redirect to a (same) page. The button does not actually have a redirect in its definition but the wizard created a branch to the same page which should work and the button has the text 'submit as SUBMIT' next to it so it appears to be set up correctly.
    I have recreated this page several times in my application and I cannot get the On-Submit process to run. However I have created a cut down version of the same page in the sample application on apex.oracle.com at http://apex.oracle.com/pls/otn/f?p=4550:1:179951678764332 and this works perfectly so I am at a loss to understand why it does not work in my application. I cannot post any part of the application itself but if anybody would like to check out page 30 of the sample application (Customer Update Test tab) updating the surnames only, using credentials ja, demo, demo this is pretty much what I have got in my application.
    Any ideas would be much appreciated?

    Thanks for the suggestions guys. I have now identified that the problem goes away when I remove the second table from my report query. The original report query retrieved data from two tables and the process was updating only one of the tables. I thought I had approached the task logically i.e. first get the report to display the records from the two tables, then get the process to update the first table and finally to modify the process further to update the second table.
    Can anyone point me to an example of multiple row updates on multiple tables using a PL/SQL function returning an SQL query?

  • Function returning query takes more time to run in Apex4.0

    Hi All,
    I created a report using function returning query. The function returns query based the parameters which returns dynamic columns. When I run the query in sql developer the query generates and returns the result in 3mins. But in apex it takes maximum of 35mins to return.
    The query will return around 10000 rows.
    Is it a performance issue in the query or in Apex?can anyone please help
    Regards
    Raj

    RajEndiran wrote:
    Hi Roel,
    Thanks much for your suggestion. I run in TOAD and got the result as
    Row 1 of 500 fetched so far in 3.31 minutes which means it queried for 500 records alone ? is that not the actual time taken to run the fulll query?That reflects the time to return the first 500 records...
    Please suggest.With all the best will in the world, if I was your user and I had to wait 3 minutes for the page to refresh, I'd steadily lose the will to live!
    As this is primarily an SQL tuning question, have a look at this message in the FAQ thread in the {forum:id=75} forum:
    {message:id=9360003}
    That should give you some pointers on the right approach.

  • Does a table/view still return records if the underlying VPD policy fails ?

    Hi All,
    I have one following question -
    Does a table or view still return records if the underlying VPD policy fails?
    I am adding one more thing here. Let us say security is being implemented using the application context and VPD.
    What would happen when application context is not set ? Would the application apply any default privilege as VPD?
    Thanks,
    Ashi

    AshiKD wrote:
    Hi All,
    I have one following question -
    Does a table or view still return records if the underlying VPD policy fails?No, you get a standard error message if the VPD function is wrong and if you won't pass the conditions of the VPD, you get nothing. That's what in general happens and should happen as well.
    >
    I am adding one more thing here. Let us say security is being implemented using the application context and VPD.
    What would happen when application context is not set ? Would the application apply any default privilege as VPD?This would be a wrong approach then. If you are truly setting a VPD, you have to make sure that the context is set and the condition variable are passed through it. This is normally done through a logon trigger so again, generically , its not possible that it would not be set. I didn't get at all what ever you said in the last line? What is "default priv for VPD" ?
    HTH
    Aman....

  • How do i skip a line if a function returns 0

    Currently i am producing a report that was passed a starting point parameter. Meaning i want an hourly wage above this number. Now in the report i run the following function. Now if the number the function return is less than 5 then i do not what that line/record to display in the report. Can anyone tell me where to look to understand how to accomplish this.
    howard
    function WAGE_TYPEFormula return Number is
    my_num number(10)
    begin
    IF :salary_type = 'BIWEEKLY' then
                   return :salary / 80;
    end if;     
    IF :salary_type = 'MONTHLY' then
                   return :salary / 173.34;
    end if;     
    IF :salary_type = 'ANNUAL' then
                   return :salary / 2080;
    end if;     
    IF :salary_type = 'HOURLY' then
         return :salary;
    end if;     
    IF :salary_type IS NULL then
                   return 0;
    end if;     

    U need to use a lexical parameter
    Go to data model and add a user paranmeter of name say
    test_param . Make sure the characer size is adequate
    and in your function have this parameter
    :test_param := 'whateever u want or dont want to display'
    and in the design model include a field with source "test_param"
    during runtime the report will display whtever is in test_param

  • Why oracle function return 4000 characters ?

    Dear All
    When I write any function to get some return value in a query, its width is set to 4000. Moreover, when i write the same query to create any LOV, it gives an error that record group field cannot be greater than 2000. Where the actual width of this field is 200 characters.
    Why function always returns 4000 characters?
    Regards
    Edited by: OraLearner on Dec 1, 2010 11:47 AM

    Because the maximum of a varchar2 in SQL is 4000 and you have no dimension in your function:
    SQL> r
      1  create or replace function myfunc(inMaxVal in number) return varchar2 is
      2    vRet varchar2(32000);
      3  begin
      4    for i in 1..inMaxVal loop
      5      vRet := vRet || '1';
      6    end loop;
      7    return vRet;
      8* end;
    Function created.
    SQL> select myfunc(4001) from dual;
    select myfunc(4001) from dual
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at "SCOTT.MYFUNC", line 7
    SQL> select myfunc(4000) from dual;
    MYFUNC(4000)
    1111111111111111111111111111111111111111111111111111
    1111111111111111111111111111111111111111111111111111so the SQL Engine have to assume your function returns 4000 bytes. If you use this function in PL/SQL it can be up to 32767 bytes:
    SQL> r
      1  begin
      2  dbms_output.put_line(substr(myfunc(4002), 1,255));
      3* end;
    11111111111111111111111111111111111111111111111111111111
    PL/SQL procedure successfully completed.cheers

  • [HELP] Procedure return records

    Hi All,
    I want to create a procedure that will return records (not only single record) base on some parameters. Is it possible?
    While i used MS SQL Server, it is just a simple way. In the body of procedure i just need to call select query with some parameters in where clause. For example:
    Create procedure GetEmployee
    @grade char(1)
    As
    Select * From Employee Where EMP_Grade=@grade
    Please help me!

    First off, what are you going to do with the records that are returned here?
    Second, you can return a REF CURSOR
    CREATE OR REPLACE PACKAGE refcursor_demo
    AS
      TYPE emp_refcursor_strong IS REF CURSOR RETURN emp%rowtype;
      TYPE emp_refcursor_weak   IS REF CURSOR;
      -- You can define either procedures that have the strongly typed
      -- REF CURSOR as an OUT parameter or you can define a function that
      -- returns the REF CURSOR.
      PROCEDURE refCursorProc( employees OUT emp_refcursor_strong );
      FUNCTION  refCursorFunc RETURN emp_refcursor_weak;
    END;
    CREATE OR REPLACE PACKAGE BODY refcursor_demo
    AS
      PROCEDURE refCursorProc( employees OUT emp_refcursor_strong )
      AS
      BEGIN
        OPEN employees FOR
          SELECT * FROM emp;
      END;
      FUNCTION refCursorFunc RETURN emp_refcursor_weak
      IS
        out_cursor emp_refcursor_weak;
      BEGIN
        OPEN out_cursor FOR
          SELECT * FROM emp;
        RETURN out_cursor;
      END;
    END;Alternately, you could return a collection, potentially in a pipelined table function.
    Justin

  • Why does the InitVXIlibrary function return -32768 ?

    Why does the InitVXIlibrary function return -32768 ?

    Hello,
    It would be extremely helpful to see a log of what is happening "behind the scenes" with the driver. To do this, you can use a utility called NI-Spy which can be launched from Start >> Programs >> National Instruments >> NI Spy or from the Measurement & Automation Explorer (MAX) utility.
    NI Spy is a Win32 application that monitors, records, and displays National Instruments API calls made by applications. Use NI Spy to quickly locate and analyze any erroneous National Instruments API calls that your application makes, and to verify that the communication with your instrument is correct.
    You can turn the log to file feature on via the Spy >> Options menu in the program. Please attach this log file to this Developer Zone post
    so that we may further help you.
    Best Regards,
    Justin Britten
    Applications Engineer
    National Instruments

Maybe you are looking for

  • Pivot Query on Oracle 10g

    Table Structure GRP_NR Values 1 A 1 B 2 A 2 B 2 C 3 A 3 B 3 C N A N B N C I would like to convert the above structure into the following. I prefer to have it as sql query, but open to plsql solution too. 1 2 3 ..................... N A A A ..........

  • Error Implicit key specification is no longer allowed in the OO context.

    Hi, I have the following error message and i cannot figure out what it is and how can i solve it: E:Implicit key specification is no longer allowed in the OO context. You must use an INDEX, KEY or FROM specification. You must use an INDEX, KEY or FRO

  • Reg passing values to a link

    Hi all, Is it possible to pass values to a link. The requirement is i need to pass some values to a standard transaction link and the values which i pass should go to the respective fields of the link. Can anyone suggest? Thanks and Regards, Sneha.

  • DMS attachment original name

    we are using ECC 5.0. During creation of DIR in DMS using cv01n we attach original files. However the actual name of these files is not display. Displaying of original file names of attachment is available in ECC6.0. How to get the same in ECC5.0? Cu

  • Question about page Orientation

    Hey guys, I have a couple of questions, I Know there are issues between Safari and acrobat's browswer plugins, without having to resort to unsinstalling adobe. Also If I do continue to use adobe reader, is there way to reverse or mirror image the pdf