REP-0737: must be a function of return type 'ref cursor.

Hi all

I have create a ref cursor query in reports 10 g. But it is giving error REP-0737: must be a function of return type 'ref cursor.

Here is my code

function QR_1RefCurDS return sys_refcursor is

 My_Cur Sys_Refcursor;
begin
  Open My_Cur for select * from scott.emp order by deptno;
  return My_Cur
end;

fate of the screen.

Ref_Cursor_in_reports10g.jpg

Oracle Forms/Reports has a complete PL/SQL engine and (only) the SQL parser.

However, the engine of forms/States PL / SQL and SQL Analyzer are at a level that was in the Oracle 8.0 database.

So, in the forms/States functions/procedures and forms/States triggers, you can not use SQL commands that did not exist in the 8.0 database.

The predefined SYS_REFCURSOR type is introduced in Oracle 9i.

Use this:

PACKAGE test_rc IS

TYPE of rc_type IS REF CURSOR RETURN emp % ROWTYPE;

END;

FUNCTION RETURN QR_1RefCurDS Test_rc.rc_type IS

test_rc.rc_type RC;

BEGIN

OPEN the RC to SELECT * FROM emp;

RETURN rc;

END;

Kind regards

Zlatko

Tags: Oracle Development

Similar Questions

  • Calling an Oracle stored procedure that returns a REF cursor

    Hi guys,.

    I'm calling an Oracle stored procedure that returns a REF CURSOR. Here is the piece of code that I'm working on:

    procedure TC307_MAIN (p_program varchar2, varchar2, varchar2, result_set OUT eng_cur p_engchgno p_project) as
    Start
    IF (p_program = 'Navybased' and p_project = 'PROTECTOR-BUILD') THEN
    result_set: = comments. Tc307_Eng_Chg_Rpt.TC307_RNZN (p_engchgno, result_set = >);
    END IF;
    end TC307_MAIN;

    procedure TC307_RNZN (p_engchgno varchar2, result_set IN OUT eng_cur) as
    Start
    end TC307_RNZN;

    PL/SQL code behind TC307_RNZN is big enough, that's why I've not stuck here. Basically, the second stored procedure executes a PLSQL statement and returns a result set. I need to return the result_set in the main proceedings based on nested else statement which I am still trying to build. I get a compilation... error can someone guide me with the correct method to call the second stored procedure and returning in the main proceedings.

    Thank you very much.

    Rohan,

    Try this

    procedure TC307_MAIN(p_program  varchar2,
                           p_project  varchar2,
                           p_engchgno varchar2,
                           result_set OUT eng_cur) as
      begin
           IF (p_program = 'RNZN' and p_project = 'PROTECTOR-BUILD') THEN
                  -- This is a procedure not a function
                         guest.Tc307_Eng_Chg_Rpt.TC307_RNZN(p_engchgno, result_set); --UR compilation error on this line*
          END IF;
      end TC307_MAIN;
    

    SS
    http://DB-Oracl.blogspot.com

  • via return Produre Ref Cursor

    Hi all

    I am trying to create the stored procedure that will return the recordset below is the code:

    create or replace procedure manager_holdings (l_table_name varchar,

    number of l_client_id

    l_process_type varchar2,

    l_process_date varchar2,

    l_enc_tenant_id varchar2,

    p_recordset OUT SYS_REFCURSOR) as

    sql_stmt varchar2 (4000);

    Start

    sql_stmt: ='

    Select * from)

    with t1 as

    (select smo.security_id, rsm.security_desc, sum (smo.closing) sum_each_sec

    of ' | l_table_name | "smo, rsm rage_security_master.

    where smo.client_id = ' | l_client_id |

    "and smo.process_type = ' |" l_process_type |

    "and smo.process_date = ' |" l_process_date |

    "and smo.enc_tenant_id = ' |" l_enc_tenant_id |

    "and smo.security_id = rsm.security_id

    Smo.security_id group, rsm.security_desc having count (smo.security_id) > 1)

    Select security_id, security_desc from t1 by security_id

    ) security_id order ';

    run immediately sql_stmt into p_recordset;

    end manager_holdings;

    but when I test it I get error below:

    Types of data inconsistent-ORA-00932: expected -. -

    ORA-06512:

    could you please help me

    Thank you

    Its resolved, I tried the below code: and his works fine. Thanks too all for help

    create or replace procedure sp_manager_holdings (l_table_name varchar2,

    number of l_client_id

    l_process_type varchar2,

    l_process_date Date,

    l_enc_tenant_id varchar2,

    p_recordset OUT SYS_REFCURSOR) as

    Start

    run immediately "start

    Open: p_recordset for

    Select security_desc, composite, manager_name, mang_composite

    Of

    (

    with t1 as

    (select smo.security_id, rsm.security_desc, sum (smo.closing) sum_each_sec of ' |)

    l_table_name |

    "smo, rsm rage_security_master.

    where smo.client_id =: l_client_id

    and smo.process_type =: l_process_type

    and smo.process_date =: l_process_date

    and smo.security_id = rsm.security_id

    and smo.enc_tenant_id =: l_enc_tenant_id

    Smo.security_id group, rsm.security_desc having count (smo.security_id) > 1)

    ,

    As T2

    (select sum (smo.closing) sum_all_sec of ' |)

    l_table_name |

    "smo".

    where smo.client_id =: l_client_id

    and smo.process_type =: l_process_type

    and smo.process_date =: l_process_date

    and smo.enc_tenant_id =: l_enc_tenant_id

    and smo.asset_id = 1),

    T3 as

    (select distinct (sm.manager_id), md.manager_name, sum (sm.closing) sum_each_mang of ' |)

    l_table_name | "sm, md manager_details where.

    SM.asset_id = 1

    and sm.client_id =: l_client_id

    and sm.process_type =: l_process_type

    and sm.process_date =: l_process_date

    and sm.enc_tenant_id =: l_enc_tenant_id

    and sm.manager_id = md.manager_id

    Sm.manager_id, md.manager_name).

    T4 in

    (

    selecT distinct sm.security_id, sm.manager_id, sum (sm.closing) sum_all_mang

    of ' | l_table_name | "sm, md manager_details.

    where security_id in

    (select smo.security_id

    of ' | l_table_name | "smo, rsm rage_security_master.

    where smo.client_id =: l_client_id

    and smo.process_type =: l_process_type

    and smo.process_date =: l_process_date

    and smo.enc_tenant_id =: l_enc_tenant_id

    and smo.security_id = rsm.security_id

    Smo.security_id group, rsm.security_desc

    having count (smo.security_id) > 1)

    and sm.manager_id in

    (select distinct (smo.manager_id)

    of ' | l_table_name | "smo".

    where smo.asset_id = 1

    and smo.client_id =: l_client_id

    and smo.process_type =: l_process_type

    and smo.process_date =: l_process_date

    and smo.enc_tenant_id =: l_enc_tenant_id

    Smo.manager_id group

    )

    and sm.client_id =: l_client_id

    and sm.process_date =: l_process_date

    and sm.process_type =: l_process_type

    and sm.enc_tenant_id =: l_enc_tenant_id

    and sm.asset_id = 1

    and sm.manager_id = md.manager_id

    Sm.security_id group, sm.manager_id

    )

    Select DISTINCT t1.security_id,

    T1.security_desc,

    Round (((t1.sum_each_sec / t2.sum_all_sec) * 100)) composite.

    T3.manager_id,

    T3.manager_name,

    Round (((t4.sum_all_mang / t3.sum_each_mang) * 100)) mang_composite

    T1, t2, t3, t4

    where t1.security_id = t4.security_id (+)

    and t3.manager_id = t4.manager_id (+)

    order of t1.security_id

    )

    ; end; »

    using p_recordset, l_client_id, l_process_type, l_process_date, l_enc_tenant_id;

    end sp_manager_holdings;

  • How to call a function that returns a SYS_REFCURSOR?

    Here's the situation.
    If I use ODP. NET to get a REF_CURSOR of a procedure in a package that it works without a hitch.

    If I use ODP .NET to run an Oracle function that returns a REF CURSOR, all sorts of things fool you.
    I use .NET 3.5 and ODP .NET version 2.112.1.2 (11 G). My Oracle database is 9.2.0.7.0

    There is this function returns a REF CURSOR.
    The code looks something like this.
    CREATE OR REPLACE FUNCTION SENDMEAREFCURSOR RETURN SYS_REFCURSOR IS
      X_REF genPkg.genericcursor;
    BEGIN
      OPEN X_REF for
        SELECT customer_id, name FROM CUSTOMERS;
      Return X_REF;
    END;
    .NET code looks like this. It's after a few adjustments.
            private static OracleDataReader FireMyFunc(OracleConnection oc)
            {
                try
                {
                    OracleCommand cmd = new OracleCommand();
                    cmd.Connection = oc;
                    //cmd.CommandText = "SELECT sendmearefcursor FROM DUAL";
                    //cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = "sendmearefcursor";
                    cmd.CommandType = CommandType.StoredProcedure;
                    OracleParameter prm = cmd.CreateParameter();
                    prm.OracleDbType = OracleDbType.RefCursor;
                    prm.ParameterName = "returncurse";
                    prm.Direction = ParameterDirection.ReturnValue;
                    cmd.Parameters.Add(prm);
                    cmd.ExecuteNonQuery();
                    return (OracleDataReader) prm.Value; //Throws an UnableToCast exception.
                }
                catch (System.Exception ex)
                {
                   Console.WriteLine(String.Format("FireMyFunc: {0}",ex.ToString()));
                    throw;
                }
            }
    What should I do to get the refCursor?

    Hello

    You can use the GetDataReader of the OracleRefCursor object to return the datareader object.

    OracleRefCursor rc is prm (OracleRefCursor). Value;
    return of rc. GetDataReader();

    HTH
    Jenny

  • PLS-00630: pipeline functions must have a collection of supported return type

    Hello, I created a TYPE of OBJECT and function PLSQL as shown below, but the function compile errors with that follows. Don't know where is the problem?
    PLS-00630: pipelined functions must have a supported collection return type
    It's about Oracle 10 g r2
    CREATE OR REPLACE TYPE cxs_plsql_profiler_object_type AS OBJECT (
       cxs_object_name      VARCHAR2 (128),
       cxs_object_type      VARCHAR2 (19),
       cxs_object_status    VARCHAR2 (7),
       cxs_read_execution   NUMBER,
       cxs_buffer_gets      NUMBER,
       cxs_disk_reads       NUMBER,
       cxs_executions       NUMBER,
       cxs_sorts            NUMBER,
       cxs_sharable_mem     NUMBER,
       cxs_address          NUMBER,
       cxs_hashvalue        NUMBER,
       cxs_osuser           VARCHAR2 (30),
       cxs_username         VARCHAR2 (30),
       cxs_module           VARCHAR2 (48),
       cxs_machine          VARCHAR2 (64),
       cxs_status           VARCHAR2 (8),
       cxs_terminal         VARCHAR2 (16),
       cxs_percentconsume   NUMBER,
       cxs_percentrepeat    NUMBER,
       cxs_plan             VARCHAR2 (120),
       target_name          VARCHAR2 (200),
       referenced_name      VARCHAR2 (200),
       referenced_type      VARCHAR2 (200),
       targetowner          VARCHAR2 (200),
       refowner             VARCHAR2 (200)
    )
    and here are the API
        FUNCTION CXS_GENERATE_PLSQL_PROFILER
    RETURN cxs_plsql_profiler_object_type
    PIPELINED IS
    out_rec cxs_plsql_profiler_object_type ;
    
    plsbatch plsql_batch;
    skount integer;
    dpendrec depend_tab;
    dkount integer;
    
    
    
    
    CURSOR objects
          IS
             SELECT object_name, object_type
               FROM dba_objects
              WHERE status = 'VALID'
                AND owner NOT IN ('SYS', 'SYSTEM')
                AND object_type IN ('PACKAGE', 'PROCEDURE', 'FUNCTION');
    
          CURSOR apis (p_object dba_objects.object_name%TYPE)
          IS
             SELECT DISTINCT *
                        FROM (SELECT   SUBSTR (a.sql_text, 1, 50) sql_text,
                                       TRUNC
                                          (  a.disk_reads
                                           / DECODE (a.executions,
                                                     0, 1,
                                                     a.executions
                                                    )
                                          ) reads_per_execution,
                                       a.buffer_gets, a.disk_reads, a.executions,
                                       a.sorts, a.sharable_mem, a.address,
                                       a.hash_value, b.osuser, b.username,
                                       b.module, b.machine, b.status, b.terminal,
                                       ROUND
                                          (cxs_db_info.kompute_percentofsql
                                                                   (a.sharable_mem),
                                           5
                                          ) percentkonsume,
                                       cxs_db_info.kount_repeat
                                                             (b.osuser,
                                                              b.terminal
                                                             ) percentr,
                                       c.operation explainplan
                                  FROM v$sqlarea a, v$session b, v$sql_plan c
                                 WHERE b.sql_hash_value = a.hash_value
                                   AND b.sql_address = a.address
                                   AND a.hash_value = c.hash_value
                                   AND a.address = c.address
                                   AND b.status = 'ACTIVE'
                                   AND UPPER (a.sql_text) LIKE
                                                            '%' || p_object || '%'
                                   AND c.ID = 0
                              ORDER BY 2 DESC)
                       WHERE ROWNUM <= 50;   --profile option
    BEGIN
    
    skount := 0;
    dkount := 0;
    
     FOR i IN objects
          LOOP
             FOR j IN apis (i.object_name)
             LOOP
                skount := skount + 1;
                plsbatch(skount).cxs_object_name  := i.object_name;
       plsbatch(skount).cxs_object_type      :=  i.object_type;
       plsbatch(skount).cxs_object_status    :=  i.object_status;
       plsbatch(skount).cxs_read_execution   := j.reads_per_execution;
       plsbatch(skount).cxs_buffer_gets      := j.buffer_gets;
       plsbatch(skount).cxs_disk_reads       := j.disk_reads;
       plsbatch(skount).cxs_executions       := j.executions;
       plsbatch(skount).cxs_sorts            := j.sorts;
       plsbatch(skount).cxs_sharable_mem     := j.sharable_mem;
       plsbatch(skount).cxs_address          := j.address;
       plsbatch(skount).cxs_hashvalue        := j.hashvalue;
       plsbatch(skount).cxs_osuser           := j.osuser;
       plsbatch(skount).cxs_username         := j.username;
       plsbatch(skount).cxs_module           := j.module;
       plsbatch(skount).cxs_machine          := j.machine;
       plsbatch(skount).cxs_status           := j.status;
       plsbatch(skount).cxs_terminal         := j.terminal;
       plsbatch(skount).cxs_percentconsume   := j.percentconsume;
       plsbatch(skount).cxs_percentrepeat    := j.percentrepeat;
       plsbatch(skount).cxs_plan             := j.explainplan;
             END LOOP;
    
             FOR dd IN dpend (i.object_name)
             LOOP
                dkount := dkount + 1;
                dependrec (dkount).target_name := dd.NAME;
                dependrec (dkount).refname := dd.referenced_name;
                dependrec (dkount).reftype := dd.referenced_type;
                dependrec (dkount).target_owner := dd.owner;
                dependrec (dkount).refowner := dd.referenced_owner;
             END LOOP;
          END LOOP;
    
    for a in 1..skount loop
    
       out_rec.cxs_object_type      := plsbatch(a).object_type;
       out_rec.cxs_object_status    := plsbatch(a).object_status;
       out_rec.cxs_read_execution   := plsbatch(a).reads_per_execution;
       out_rec.cxs_buffer_gets      := plsbatch(a).buffer_gets;
       out_rec.cxs_disk_reads       := plsbatch(a).disk_reads;
       out_rec.cxs_executions       := plsbatch(a).executions;
       out_rec.cxs_sorts            := plsbatch(a).sorts;
       out_rec.cxs_sharable_mem     := plsbatch(a).sharable_mem;
       out_rec.cxs_address          := plsbatch(a).address;
       out_rec.cxs_hashvalue        := plsbatch(a).hashvalue;
       out_rec.cxs_osuser           := plsbatch(a).osuser;
       out_rec.cxs_username         := plsbatch(a).username;
       out_rec.cxs_module           := plsbatch(a).module;
       out_rec.cxs_machine          := plsbatch(a).machine;
       out_rec.cxs_status           := plsbatch(a).status;
       out_rec.cxs_terminal         := plsbatch(a).terminal;
       out_rec.cxs_percentconsume   := plsbatch(a).percentconsume;
       out_rec.cxs_percentrepeat    := plsbatch(a).percentrepeat;
       out_rec.cxs_plan             := plsbatch(a).explainplan;
       PIPE ROW(out_rec);
    end loop;
    
    
    for b in 1..dkount loop
        out_rec.target_name := dd.NAME;
                out_rec.refname := dependrec (b).referenced_name;
                out_rec.reftype := dependrec (b).referenced_type;
                out_rec.target_owner := dependrec (b).owner;
                out_rec.refowner := dependrec (b).referenced_owner;
                PIPE ROW(out_rec);
     end loop;
    RETURN;
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.format_error_backtrace);
    DBMS_OUTPUT.PUT_LINE(SQLCODE);
    DBMS_OUTPUT.PUT_LINE(SQLERRM);
    END; 
    and here's tradtional types of tables that are used in the code above.
     TYPE type_plsql_rec IS RECORD (
       cxs_object_name      VARCHAR2 (128),
       cxs_object_type      VARCHAR2 (19),
       cxs_object_status    VARCHAR2 (7),
       cxs_read_execution   NUMBER,
       cxs_buffer_gets      NUMBER,
       cxs_disk_reads       NUMBER,
       cxs_executions       NUMBER,
       cxs_sorts            NUMBER,
       cxs_sharable_mem     NUMBER,
       cxs_address          NUMBER,
       cxs_hashvalue        NUMBER,
       cxs_osuser           VARCHAR2 (30),
       cxs_username         VARCHAR2 (30),
       cxs_module           VARCHAR2 (48),
       cxs_machine          VARCHAR2 (64),
       cxs_status           VARCHAR2 (8),
       cxs_terminal         VARCHAR2 (16),
       cxs_percentconsume   NUMBER,
       cxs_percentrepeat    NUMBER,
       cxs_plan             VARCHAR2 (120)
       );
    
       TYPE plsql_batch IS TABLE OF type_plsql_rec
          INDEX BY BINARY_INTEGER;
          
          
           TYPE type_depend_tab IS RECORD (
          target_name    dba_dependencies.NAME%TYPE,
          refname        dba_dependencies.referenced_name%TYPE,
          reftype        dba_dependencies.referenced_type%TYPE,
          target_owner   dba_dependencies.owner%TYPE,
          refowner       dba_dependencies.referenced_owner%TYPE
       );
    
       TYPE depend_tab IS TABLE OF type_depend_tab
          INDEX BY BINARY_INTEGER;
    Thank you for your time in reading this post

    R

    Johan says:
    Sorry!.
    Actually, I meant

    I thought as well.

    Typos can be expensive however. As a probe of NASA Mars in 99, which was lost due to a simple mathematical error - a confusion between English and metric units. ;-)

    Or screw up a server in reason to use a Unix fork() where the client process think that it is the parent and the beginning more children who believe they are also parents of spawning... (one of my mistakes of kewlest never) :-)

  • REF CURSOR as a return of a function in SQL developer

    Hi team,

    I have a function which returns a Ref from a function slider while getting an entry number. But once I have create an implementation of single test on it with a valid entry that he throws error like below and have failed. My SQL developer version is 4.0.2.15.21 and it turns on a Linux OS (GNU/Linux 3.10.0 - 123.6.3.el7.x86_64). Here is the error I get.

    Cannot be converted to NUMBER <oracle.jdbc.driver.OracleResultSetImpl@5925237>.

    oracle.dbtools.raptor.datatypes.oracle.sql.NUMBER.customUnscaledInternalValue(NUMBER.java:93)

    oracle.dbtools.raptor.datatypes.oracle.sql.NumericDatum.customInternalValue(NumericDatum.java:37)

    oracle.dbtools.raptor.datatypes.impl.DataTypeImpl.customInternalValueFilter(DataTypeImpl.java:411)

    oracle.dbtools.raptor.datatypes.impl.DataTypeImpl.getInternalValue(DataTypeImpl.java:399)

    oracle.dbtools.raptor.datatypes.impl.DataValueImpl. < init > (DataValueImpl.java:55)

    oracle.dbtools.raptor.datatypes.impl.DataTypeImpl.customDataValue(DataTypeImpl.java:196)

    oracle.dbtools.raptor.datatypes.impl.DataTypeImpl.getDataValue(DataTypeImpl.java:178)

    Oracle.DBTools.unit_test. Runner.UtRunnerImplIterator$ UtRunnerImplObject.getDynamicValueByName (UtRunnerImplIterator.Java:324)

    Oracle.DBTools.unit_test. Runner.UtRunnerImplIterator$ UtRunnerImplObject.mapDynamicValueByName (UtRunnerImplIterator.Java:301)

    Oracle.DBTools.unit_test. Runner.UtRunnerImplIterator$ UT...

    Please help me out here.

    Please do not post double fillet.

    Mark this thread ANSWER and continue to use your other thread.

    Function taking as input ref cursor but throwing error exit

  • Using the function PLSQL return Record Type Index of Tables in ADF

    I have a PLSQL function, a return type. My ultimate goal is to take this binary integer index Table and print it on the screen...

    CREATE OR REPLACE PACKAGE my_pkg IS
     
    TYPE t_col IS RECORD(
     
    i NUMBER,
     
    n VARCHAR2(30));
     
    TYPE t_nested_table IS TABLE OF t_col;
     
      FUNCTION return_table RETURN t_nested_table ;
    END my_pkg;


    OPTION 1:

    1) has anyone got best practices to accept plsql RECORDS returned by a function?

    Here is an example.

    http://adfpractice-Fedor.blogspot.SG/2013/01/working-with-PLSQL-procedures-in-ADF-BC.html

    But it will be a lot of work... first of all accept the results in a loop... then store in a temporary storage can be a few VO or global temporary table and then display them on the page


    OPTION 2:

    Using the functions PIPLELINED and use in the select statement.  While I can use this select statement in the SQL query to create VO... and drag and drop the VO...

    CREATE OR REPLACE PACKAGE my_pkg IS
     
    TYPE t_col IS RECORD(
     
    i NUMBER,
     
    n VARCHAR2(30));
     
    TYPE t_nested_table IS TABLE OF t_col;
     
      FUNCTION return_table RETURN t_nested_table PIPELINED;
    END my_pkg;


    select * from table(my_pkg.return_table);


    Wow... I'm so smart! .. really possible?  who is the best/possible/recommended option?

    I'm sure that will be the question most read by many who wants to use PLSQL instead of JAVA to the treatment and CHOSEN to use only to display the output of the PLSQL functions or procedures.


    Thank you

    Rahul


    Dario

    Do you mean the scope of the defined Type pkg will be finished?

    I created guy outside the pkg as 'Create Type' if it works in this case?

    Yes, level objects schema (created with "create or replace type...") can be used in java and this can work.

    I think that then the scope of this TYPE will remain until the user session passes.

    Object definitions is not worn, but have their bodies.

    So, if you instantiate the data level object type schema in a plsql function, scope of this object is this function.

    Of course, if you instantiate the object as a variable package, then life of this object is equal to the lifetime of the package (which usually equals life of session db).

    Dario

  • Function that returns the results of a select statement

    Hello

    I would like to create a feature on the famous HR Departments oracle table to select * from him. I don't know how to do it.

    Is someone can help me?.

    Thank you

    Oracle stored functions cannot return result sets directly but can return the REF CURSOR. Please read [optimize result set retrieval using ODP.NET and Ref Cursor | http://www.oracle.com/technology/pub/articles/mastering_dotnet_oracle/williams_refcursors.html] which gives complete examples in PL/SQL for the side Server and VB. NET client side.

  • Request report - use the function that returns the cursor

    My requirement is to create a report, which the source will be a function that returns a cursor (the type of cursor is ref cursor).
    How this can be done?

    for example. function my_func (pol_no in number) return cur_type < ref cursor >

    Edited by: viveks on October 27, 2009 10:09

    Better to look at a function that returns a query, or use a hose to treat your cursor returned, because the APEX at the moment can NOT handle the sliders in reports...

    Thank you

    Tony Miller
    Webster, TX

  • How to pass a REF CURSOR from a function

    I tried to compile the following function:

    CREATE or REPLACE FUNCTION example
    RETURN REFCURSOR
    IS
    heart REFCURSOR;
    BEGIN
    OPEN FOR heart
    "SELECT x FROM table";
    RETURN cur;.
    END;

    but I get:

    PLS-00201: identifier 'REFCURSOR' must be declared.

    Can you help me in the right syntax? I never return a REF CURSOR to a function.
    Is my Version of Oracle 8.1.7

    Thank you!

    You cannot use SYS_REFCURSOR in Oracle 8i.
    The work is approximately as follows

    create or replace package my_pk as
    type my_cur is REF CURSOR;
    end my_pk;
    
    -- Now write your function
    create or replace function my_func return my_pk.my_cur
    as
    l_cur my_pk.my_cur;
    begin
    open l_cur for select * from table_name;
    return l_cur;
    end my_func;
    

    Thank you
    Andy

  • Create the object type with a member function that returns an array of the object type

    Hello

    Is possible to compile code like this in Oracle SQL?

    CREATE OR REPLACE TYPE type_obj IS OBJECT (
      MEMBER FUNCTION f RETURN table_obj
    );
    
    CREATE OR REPLACE TYPE table_obj AS TABLE OF type_obj;
    
    

    In Java, it would be possible.

    Thanks in advance

    Circular dependencies must be resolved by means of REF pointers and incomplete type definition.

    See: Oracle objects management

    CREATE or REPLACE TYPE type_obj;

    /

    CREATE or REPLACE TYPE table_obj AS TABLE OF ref type_obj;

    /

    CREATE or REPLACE TYPE type_obj () IS OBJECT

    fake number

    Table_obj RETURN of the FUNCTION MEMBER f

    );

    /

    Now, it must implement the body of type.

    Note that a table of the REFs is not very useful in the plain of PL/SQL, the underlying data must be stored in a nested table if you want to use.

  • Message box in function that returns a list deletes the created list... (Dialog box)

    Hello

    I work with a complex dialogue, its purpose is to manage a section in the PDF file.

    I use a "mclv" object in the dialog box to represent data entries in the PDF file in order to manage the result in another section.

    I created a function that creates the list based on a previous section in the PDF object, the function works perfectly well.

    But I have a small question, the function used to create the list of the dialog box object performs a check with the former front list created, as appropriate,

    and if in any case it is different from the old list, I need to warn the user that the list has changed and if there were any changes applied to the result it will be returned to zero and must be recreated.

    But when the poping that message box, all lists are deleted and nothing is displayed in the objects 'mclv.

    If I remove the message box, the lists are all very well...

    Is there anyone who have come across something like this before? If so, any solution to this problem?

    I asked my question a bit too quickly, I already found a work around

    But I still don't understand why he behaves like that tho...

    I just thought how to work around this problem.

    If anyone has encountered this problem can use this solution:

    Instead of having the message inside the function to return box, I declared a global Boolean variable to the Script object

    If the message box must be displayed, the Boolean value is set to True

    Once in the initialize event of the dialog box, if the value Boolean true I call the message box and reset the value Boolean false

  • Selection of a function that returns a sys refcursor or alternative

    I have a query that returns a result set of three columns, namely the SSN, the PAID_YEAR and the PAID_TOTAL. This query, I can:

    1. Create a view and then question him.
    2. Create a function result set and return

    If I go the first way, that a simple request like this takes more than 20 seconds:

    SELECT PAID_YEAR,PAID_TOTAL FROM VIEW_1 WHERE SSN=12345678912882;

    I know it's because when I query a view engine first brings all the rows in the view and then filters the lines for the criteria provided.

    If I go the second way I can send only a parameter and make the engine look for only the rows that match the condition and the Recordset. But I don't know how then SELECT this result set returned. I took a look at the tables in pipeline, but do not understand how to their advantage. So my final question is if it is somehow possible to select from the result set returned by a function like this:

    SELECT * FROM FUNCTION_1(12132323232).

    If Yes, then how, if not, what would be another way?

    I know it's because when I query a view engine first brings all the rows in the view and then filters the lines for the criteria provided.

    No - you don't "know that" because it is not true. Just check out the plan of the command explain to yourself. Oracle can always use appropriate indexes so that only the needed rows are returned.

    So my final question is if it is somehow possible to select from the result set returned by a function like this:

    SELECT * FROM FUNCTION_1(12132323232).
    

    No - you can't do it like that. You must use the TABLE function to process the result of the function defined in a table:

    'SELECT * FROM TABLE(FUNCTION_1(12132323232)).

    -type to match record emp
    create or replace type emp_scalar_type as an object
    (EMPNO NUMBER 4,
    ENAME VARCHAR2 (10),
    USE VARCHAR2 (9).
    MGR NUMBER 4,
    HIREDATE DATE,
    NUMBER OF SAL (7, 2)
    NUMBER OF COMM (7, 2)
    DEPTNO NUMBER (2)
    )
    /

    -records of the emp table
    create or replace type emp_table_type to table of emp_scalar_type
    /

    -function of pipelined

    create or replace function get_emp (p_deptno number)
    return emp_table_type
    PIPELINED
    as
    TYPE EmpCurTyp IS REF CURSOR RETURN emp % ROWTYPE;
    emp_cv EmpCurTyp;
    l_rec emp % rowtype;
    Start
    Open emp_cv SELECT * from emp where deptno = p_deptno;
    loop
    extract the emp_cv in l_rec;
    When the output (emp_cv % notfound);
    line of conduct (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))

  • RETURN type of function table

    Hello

    I read conflicting information about the return type that has a table function must or may use.

    First, I am a student of a book that says:

    Function in pipeline returns the data types:

    The main constraint for the pipeline functions, it is the return type must be a collection type autonomous which can be used in SQL - i.e. a VARRAY or table nested.

    and then in the next sentence...

    More precisely a pipeline function can return the following:

    A stand-alone nested table or VARRAY, defined at the schema level.

    A nested table or VARRAY that has been declared in a package type.

    This seems to go against the first quoted sentence.

    Now, before reading the above text I had done just my own test to see if a packed type would work because I thought I had read somewhere that it would not, and he does not (the test code and this output is at the end of this question). When I arrived in the text above, after my test, so I was naturally confused.

    So, I'm going to PL/SQL reference that says:

    RETURN data type

    The data type of the value returned by a function table in pipeline must be a type collection defined either at the level of schema or within a package (therefore, it cannot be a type of associative array).

    I tried to call a function that returns a collection of VARRAY type packaged in both SQL and PL/SQL (of course below is SQL all in any case) and no work.

    Now I'm wondering what is a TABLE function must use a schema type and a function table in pipeline can use a packaged type?  I see that I created and called a function table but examples of Oracle see the creation and use of a function table in pipeline.

    Edit: I should add that I read the following sentence in the SF book on p609 in * table functions: "this type of nested table must be defined as an element of level diagram, because the SQL engine must be able to resolve a reference to a collection of this kind."

    So that it begins to resemble table functions should return a schema type and pipelined table functions, perhaps because that they don't in fact return a collection, rather they return (RowSource) content, can use the schema types or types of packages. Is this correct?

    Can someone clarify this for me please?

    Thank you in advance,

    J

    CREATE OR REPLACE PACKAGE PKGP28M

    VAT-type is varray (5) number;

    END;

    /

    DISPLAY ERRORS

    create or replace type VAT is varray (5) number;

    /

    display errors

    create or replace function tabfunc1 return pkgp28m.vat as

    numtab pkgp28m.vat:=pkgp28m.vat();

    Start

    numtab.extend (5);

    because loop me in 1.5

    numtab (i): = trunc (dbms_random. Value (1.5));

    end loop;

    Return numtab;

    end;

    /

    display errors

    create or replace function tabfunc2 as return VAT

    numtab vat:=vat().

    Start

    numtab.extend (5);

    because loop me in 1.5

    numtab (i): = trunc (dbms_random. Value (1.5));

    end loop;

    Return numtab;

    end;

    /

    display errors

    exec dbms_output.put_line (' call tabfunc1 (returns the packaged type) :');)

    Select * from table (tabfunc1)

    /

    exec dbms_output.put_line (' call tabfunc2 (returns the type of schema) :');)

    Select * from table (tabfunc2)

    /

    declare

    RC sys_refcursor;

    number of v;

    Start

    dbms_output.put_line (' in anonymous block1 - open rc to select in the table (tabfunc1) (returns the packaged type) :');)

    Open rc to select table column_value (tabfunc1);

    loop

    extract the rc in v;

    When the output rc % notfound;

    dbms_output.put_line (' > ' | to_char (v));

    end loop;

    close the rc;

    end;

    /

    declare

    RC sys_refcursor;

    number of v;

    Start

    dbms_output.put_line (' in anonymous block2 - open rc to select in the table (tabfunc2) (returns the type of schema) :');)

    Open rc to select table column_value (tabfunc2);

    loop

    extract the rc in v;

    When the output rc % notfound;

    dbms_output.put_line (' > ' | to_char (v));

    end loop;

    close the rc;

    end;

    /

    Scott@ORCL > @C:\Users\J\Documents\SQL\test29.sql

    Package created.

    No errors.

    Type of creation.

    No errors.

    The function is created.

    No errors.

    The function is created.

    No errors.

    the call of tabfunc1 (returns the packaged type):

    PL/SQL procedure successfully completed.

    Select * from table (tabfunc1)

    *

    ERROR on line 1:

    ORA-00902: invalid data type

    the call of tabfunc2 (returns the type of schema):

    PL/SQL procedure successfully completed.

    COLUMN_VALUE

    ------------

    1

    4

    1

    1

    3

    In anonymous block1 - open rc to select in the table (tabfunc1) (returns the packaged type):

    declare

    *

    ERROR on line 1:

    ORA-00902: invalid data type

    ORA-06512: at line 6

    In anonymous block2 - open rc to select in the table (tabfunc2) (returns the type of schema):

    > 1

    > 2

    > 4

    > 2

    > 3

    PL/SQL procedure successfully completed.

    Post edited by: Jason_942375

    But the compilation of the PIPELINED WILL CREATE the schematic function types automatically. And the TABLE function, applied to the PIPELINED function, use these types of hidden patterns.

  • How to the return type of function from PL/SQL

    Hello

    I need to create a function that returns a list of ID, which is stored in a type T_IDs, something like:

    search function (searchstring in varchar2) return to T_IDs

    I have a little problem with the type within the body of the function using a select statement and filling

    Select the id of the table where the text as searchstring.

    which is to select a list of IDS corresponding to the where clause. Is it possible to use select in or should I go for another mechanism?

    Thanks for all the ideas.

    Bulk Collect works for me...

    SQL> create type t_ids as table of number;
      2  /
    
    Type created.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  create or replace function get_ids(deptno in number) return t_ids is
      2    ids t_ids;
      3  begin
      4    select empno
      5    bulk collect into ids
      6    from   emp
      7    where  deptno = get_ids.deptno;
      8    return ids;
      9* end;
    SQL> /
    
    Function created.
    
    SQL> select * from table(get_ids(10));
    
    COLUMN_VALUE
    ------------
            7782
            7839
            7934
    

    However, I would rarely use such a data collection, as it fills with PGA in memory and passing a lot of data between SQL and PL/SQL. I must have a just cause and justified in wanting to do things this way.

Maybe you are looking for