Cursor as an IN Parameter

Hello, I want to know if is possible to have (and the way to do it)
a Cursor as an IN parameter. For example to
have a cursor for insert some of its fields in a table. I have tried using a REF CURSOR in a package but it only works for returning a cursor reference to the caller program.Thanks,
Cesar.
null

Thank you for your reply, Yuancai. It would be very useful if the OLE DB team added such an interface to future versions of TCommand. However, for the time being what is the preferred technique for passing large amounts of data to a stored procedure? For instance we have a number of tables that have fifty or more columns. It would be awkward to call a stored procedure with this many parameters. Ideally, one would want to create a structure as a User Defined Type and pass that as a parameter.
One approach we though of was to pass a XML string though a CLOB parameter and parse it in either a PL/SQL or Java stored procedure. However, while this approach is novel it is not standard. I've found it best to use standard techniques where possible. Any insight you could give would be appreciated.
Thanks,
Bryan Wood

Similar Messages

  • Does OraOLEDB support passing a Ref Cursor as an IN parameter of a Stored Procedure?

    We have a number of Stored Procedures that take a Cursor as an input parameter. Is it possible to call a Stored Procedure of this type with OraOLEDB? If so could you provide a quick sample using VC++/ATL?
    Thanks...

    Thank you for your reply, Yuancai. It would be very useful if the OLE DB team added such an interface to future versions of TCommand. However, for the time being what is the preferred technique for passing large amounts of data to a stored procedure? For instance we have a number of tables that have fifty or more columns. It would be awkward to call a stored procedure with this many parameters. Ideally, one would want to create a structure as a User Defined Type and pass that as a parameter.
    One approach we though of was to pass a XML string though a CLOB parameter and parse it in either a PL/SQL or Java stored procedure. However, while this approach is novel it is not standard. I've found it best to use standard techniques where possible. Any insight you could give would be appreciated.
    Thanks,
    Bryan Wood

  • Cursor bound to out parameter with Connection Pool

    Is it possible to retrieve a cursor bound to an out parameter when using the thin
    driver to establish the connection pool to the database? I am currently using
    the JDriver to connect create the pool and the pool driver to connect from the
    app to the connection pool. We'd like to avoid using the Oracle client if possible.
    Currently I register the out parameter as java.sql.Types.OTHER, then call getResultSet(1)
    on the weblogic.jdbc.pool.CallableStatement object. But it breaks when I change
    the connection pool to use the thin driver. The error is at the bottom of this
    post.
    I think I could possibly get the current pool driver to work if can find some
    documentation on these two methods:
    void registerOutParameter(int i, int j, int k, int l)
    void registerOutParameter(int i, int sqlType, java.lang.String typeName)
    I have no idea what to put in for the ints in the first method or for sqlType
    or typeName. Can anyone point me to where I can find this documentation?
    E-docs mentions this class: weblogic.jdbc.vendor.oracle.OracleCallableStatement.
    (http://edocs.bea.com/wls/docs61/jdbc/thirdparty.html#1023867). Should I consider
    this? If so where is it?
    Thanks a lot,
    Matt Savino
    <<< error when using thin driver >>>
    preparing callable stmt
    callable stmt prepared, java.sql.Types.OTHER = 1111
    java.sql.SQLException: Invalid column type
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:273)
    at oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.java:4560)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:225)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:350)
    at weblogic.jdbc.pool.Statement.registerOutParameter(Statement.java:617)
    at jsp_servlet._reportmanager.__thin_outputresultset._jspService(__thin_outputresultset.java:145)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:263)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:200)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:2390)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:1959)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)

    Thanks Joe, your answer pointed me in the right direction. Just in case anyone
    wants to know, the solution took two changes:
    CHANGE
    cStat.registerOutParameter(1, java.sql.Types.OTHER);
    TO
    cStat.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
    (cStat is an instance of weblogic.jdbc.pool.CallableStatement)
    AND
    rs = cStat.getResultSet(1);
    TO
    rs = cStat.getCursor(1);
    Thanks again,
    Matt
    Joseph Weinstein <[email protected]> wrote:
    Hi Matt.
    Look at the Oracle thin driver documentation to determine what type you
    should define in the registerOutParameter call. We use 'OTHER', but
    their driver may use something else for CURSOR output parameters.
    joe
    Matt Savino wrote:
    Is it possible to retrieve a cursor bound to an out parameter whenusing the thin
    driver to establish the connection pool to the database? I am currentlyusing
    the JDriver to connect create the pool and the pool driver to connectfrom the
    app to the connection pool. We'd like to avoid using the Oracle clientif possible.
    Currently I register the out parameter as java.sql.Types.OTHER, thencall getResultSet(1)
    on the weblogic.jdbc.pool.CallableStatement object. But it breaks whenI change
    the connection pool to use the thin driver. The error is at the bottomof this
    post.
    I think I could possibly get the current pool driver to work if canfind some
    documentation on these two methods:
    void registerOutParameter(int i, int j, int k, int l)
    void registerOutParameter(int i, int sqlType, java.lang.String typeName)
    I have no idea what to put in for the ints in the first method or forsqlType
    or typeName. Can anyone point me to where I can find this documentation?
    E-docs mentions this class: weblogic.jdbc.vendor.oracle.OracleCallableStatement.
    (http://edocs.bea.com/wls/docs61/jdbc/thirdparty.html#1023867). Should
    I consider
    this? If so where is it?
    Thanks a lot,
    Matt Savino
    <<< error when using thin driver >>>
    preparing callable stmt
    callable stmt prepared, java.sql.Types.OTHER = 1111
    java.sql.SQLException: Invalid column type
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:273)
    at oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.java:4560)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:225)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:350)
    at weblogic.jdbc.pool.Statement.registerOutParameter(Statement.java:617)
    at jsp_servlet._reportmanager.__thin_outputresultset._jspService(__thin_outputresultset.java:145)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:263)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:200)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:2390)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:1959)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    PS: Folks: BEA WebLogic is expanding rapidly, with both entry and advanced
    positions
    for people who want to work with Java, XML, SOAP and E-Commerce infrastructure
    products.
    We have jobs at Nashua NH, Liberty Corner NJ, San Francisco and San Jose
    CA.
    Send resumes to [email protected]

  • ResultSet of a cursor as an out parameter

    How can you return a cursor or a resultSet as an OUT parameter? - Any info will be greatly appreciated. A code ex will be great
    vj

    Assuming you mean as an output parameter of pl/sql procedure being called from pl/sql...
    declare
      type refcur_type is ref cursor;
      type tab_user_tables_type is table of user_tables%rowtype index by binary_integer;
      refcur_user_tables refcur_type;
      tab_user_tables tab_user_tables_type;
      row_user_tables user_tables%rowtype;
      procedure get (
        out_refcur_user_tables out refcur_type,
        out_tab_user_tables out tab_user_tables_type) is
      begin
        for row_user_tables in (select * from user_tables) loop
          out_tab_user_tables(nvl(out_tab_user_tables.count, 0) + 1) := row_user_tables;
        end loop;
        open out_refcur_user_tables for select * from user_tables;
      end get;
    begin
      get(refcur_user_tables, tab_user_tables);
      dbms_output.put_line('from table ...');
      for i in 1 .. tab_user_tables.count loop
        dbms_output.put_line(tab_user_tables(i).table_name);
      end loop;
      dbms_output.put_line('from reference cursor ...');
      loop
        fetch refcur_user_tables into row_user_tables;
        exit when refcur_user_tables%notfound;
        dbms_output.put_line(row_user_tables.table_name);
      end loop;
    end;

  • Unable to use ref cursor as a input parameter at the time of inserting reco

    Hi
    i am unable to use ref cursor when inserting the data to oracle 11g from visual studio 2008. please help me as early as possible my code is bellows
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Web.Configuration;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    public partial class App_frmTest : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    protected void btnClick_Click(object sender, EventArgs e)
    OracleCommand cmd=new OracleCommand();
    Data objdata = new Data();
    int i = 0;
    string constr = "Data Source=Cwc;User Id=scott; Password=tiger;";// enlist=false; pooling=false;
    OracleConnection con = new OracleConnection(constr);
    /*Connection Open*/
    con.Open();
    cmd.Connection = con;
    /*Connection Open End*/
    /*Select Through Ref Cursor*/
    cmd.CommandText = "scott.TEST_USER.getUSER";
    cmd.CommandType = CommandType.StoredProcedure;
    OracleParameter p_rc = cmd.Parameters.Add("p_rc", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Output);
    OracleParameter p_rc1;
    if (TextBox1.Text == "")
    p_rc1 = cmd.Parameters.Add("p_rc", OracleDbType.Int16, DBNull.Value, ParameterDirection.Input);
    else
    p_rc1 = cmd.Parameters.Add("p_rc", OracleDbType.Int16, Convert.ToInt16(TextBox1.Text), ParameterDirection.Input);
    // OracleParameter p_rc1 = cmd.Parameters.Add("p_rc", OracleDbType.Int16, 2, ParameterDirection.Input);
    OracleDataReader reader = cmd.ExecuteReader();
    DataSet ds = new DataSet();
    DataTable dt1 = new DataTable();
    dt1.Load(reader);
    ds.Tables.Add(dt1);
    GridView1.DataSource = ds;
    GridView1.DataBind();
    cmd.Parameters.Clear();
    con.Close();
    con.Dispose();
    OracleCommand cmd1 = new OracleCommand();
    OracleConnection con1 = new OracleConnection(constr);
    con1.Open();
    cmd1.Connection = con1;
    cmd1.CommandText = "scott.TEST_USER.ADDUSER";
    cmd1.CommandType = CommandType.StoredProcedure;
    OracleParameter P_ADDUSER = cmd1.Parameters.Add("P_ADDUSER", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Input);
    cmd1.ExecuteNonQuery(); // i am getting error when executing this line
    Server Error in '/CWC' Application.
    Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    Exception Details: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    Source Error: 
    Line 77: OracleParameter P_ADDUSER = cmd1.Parameters.Add("P_ADDUSER", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Input);
    Line 78: //OracleParameter P_MSG = cmd.Parameters.Add("P_MSG", OracleDbType.Varchar2, DBNull.Value, ParameterDirection.Output);
    Line 79: cmd1.ExecuteNonQuery();
    Line 80:
    Line 81: DataTable dt = new DataTable();
    Source File: d:\CWC\App\frmTest.aspx.cs    Line: 79 
    Stack Trace: 
    [AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.]
    Oracle.DataAccess.Client.OpsSql.ExecuteNonQuery(IntPtr opsConCtx, IntPtr& opsErrCtx, IntPtr& opsSqlCtx, IntPtr& opsDacCtx, IntPtr opsSubscrCtx, Int32& isSubscrRegistered, Int32 bchgNTFNExcludeRowidInfo, Int32 bQueryBasedNTFNRegistration, Int64& query_id, OpoSqlValCtx*& pOpoSqlValCtx, String pCommandText, IntPtr& pUTF8CommandText, IntPtr[] pOpoPrmValCtx, String[] ppOpoPrmRefCtx, OpoMetValCtx*& pOpoMetValCtx, Int32 prmCnt, Int32 bFromPool) +0
    Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery() +4731
    App_frmTest.btnClick_Click(Object sender, EventArgs e) in d:\CWC\App\frmTest.aspx.cs:79
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

    Hi;
    Its better to ask it at visual studio forum site:http://social.msdn.microsoft.com/Forums/en-US/category/visualstudio
    Regard
    Helios

  • Returning a Ref cursor as an OUT Parameter

    Hi Guys
    I have defined 2 Types and 2 Ref cursors as shown below.I have written a procedure having 2 IN and 2 OUT parameters which are of type Ref cursors and return records to the calling client. My question is how can i test for the output of the two cursors here in pl/sql?.. also i should not close the sursors.. right?..its the job of the calling client as per my knowledge....Please suggest
    TYPE type_dept_Rec IS RECORD(deptNo varchar2);
    TYPE type_prod_Rec IS RECORD(prodType varchar2);
    TYPE deptCursor IS REF CURSOR RETURN type_dept_Rec;
    TYPE prodCursor IS REF CURSOR RETURN type_prod_Rec;
    PROCEDURE TEST (pinCode IN varchar2, prodType IN number, deptCursor OUT deptType, productCursor OUT deptType) IS
    BEGIN
    OPEN deptCursor FOR SELECT
    deptNo
    from
    DEPT
    where
    pinCode = pinCode;
    OPEN productCursor FOR SELECT
    prodCode
    from
    PROD
    where
    prodType = prodType;
    end;

    A Correction to the above code snippet
    Hi Guys
    I have defined 2 Types and 2 Ref cursors as shown below.I have written a procedure having 2 IN and 2 OUT parameters which are of type Ref cursors and return records to the calling client. My question is how can i test for the output of the two cursors here in pl/sql?.. also i should not close the sursors.. right?..its the job of the calling client as per my knowledge....Please suggest
    TYPE type_dept_Rec IS RECORD(deptNo varchar2);
    TYPE type_prod_Rec IS RECORD(prodType varchar2);
    TYPE deptCursor IS REF CURSOR RETURN type_dept_Rec;
    TYPE prodCursor IS REF CURSOR RETURN type_prod_Rec;
    PROCEDURE TEST (pinCode IN varchar2, prodType IN number, deptCursor OUT deptCursor, productCursor OUT prodCursor) IS
    BEGIN
    OPEN deptCursor FOR SELECT
    deptNo
    from
    DEPT
    where
    pinCode = pinCode;
    OPEN productCursor FOR SELECT
    prodCode
    from
    PROD
    where
    prodType = prodType;
    end

  • To  use cursor as an OUTPUT paramete in Oracle Store Procedure

    I want to return a ref cursor from an oracle store procedure. Is is possible? How? Syntax?

    yes I think it is possible its syntax is
    CREATE OR REPLACE
    PROCEDURE GetEmpRS1 (p_recordset1 OUT SYS_REFCURSOR,
                  p_recordset2 OUT SYS_REFCURSOR,
                  PARAM IN STRING) AS
    BEGIN
      OPEN p_recordset1 FOR
      SELECT RET1
        FROM MYTABLE
        WHERE LOOKUPVALUE > PARAM;
      OPEN p_recordset2 FOR
      SELECT RET2
       FROM MYTABLE
       WHERE LOOKUPVALUE >= PARAM;
    END GetEmpRS1;

  • Performance problem with sproc and out parameter ref cursor

    Hi
    I have sproc with Ref Cursor as an OUT parameter.
    It is extremely slow looping over the ResultSet (does it record by record in the fetch).
    so I have added setPrefetchRowCount(100) and setPrefetchMemorySize(6000)
    pseudo code below:
    string sqlSmt = "BEGIN get_tick_data( :v1 , :v2); END;";
    Statement* s = connection->createStatement(sqlStmt);
    s->setString(1, i1);
    // cursor ( f1 , f2, f3 , f4 , i1 ) f for float type and i for interger value.
    // 5 columns as part of cursor with 4 columns are having float value and
    // 1 column is having int value assuming 40 bytes for one rec.
    s->setPrefetchRowCount (100);
    s->PrefetchMemorySize(6000);
    s->registerOutParam(2,OCCICURSOR);
    s->execute();
    ResultSet* rs = s->getCursor(2);
    while (rs->next()) {
    // do, and do v slowly!
    }

    Hi,
    I have the same problem. It seems, when retrieving cursor, that "setPrefetchRowCount" is not taking into account by OCCI. If you have a SQL statement like "SELECT STR1, STR2, STR3 FROM TABLE1" that works fine but if your SQL statement is a call to a stored procedure returning a cursor each row fetching need a roudtrip.
    To avoid this problem you need to use the method "setDataBuffer" from the object "ResultSet" for each column of your cursor. It's easy to use with INT type and STRING type, a lit bit more complex with DATE type. But until now, I'm not able to do the same thing with REF type.
    Below a sample with STRING TYPE (It's assuming that the cursor return only one column of STRING type):
    try
      l_Statement = m_Connection->createStatement("BEGIN :1 := PACKAGE1.GetCursor1(:2); END;");
      l_Statement->registerOutParam(1, oracle::occi::OCCINUMBER, sizeof(l_CodeErreur));
      l_Statement->registerOutParam(2, oracle::occi::OCCICURSOR);
      l_Statement->executeQuery();
      l_CodeErreur = l_Statement->getNumber(1);
      if ((int) l_CodeErreur     == 0)
        char                         l_ArrayName[5][256];
        ub2                          l_ArrayNameSize[5];
        l_ResultSet  = l_Statement->getCursor(2);
        l_ResultSet->setDataBuffer(1, l_ArrayName,   OCCI_SQLT_STR, sizeof(l_ArrayName[0]),   l_ArrayNameSize,   NULL, NULL);
        while (l_ResultSet->next(5))
          for (int i = 0; i < l_ResultSet->getNumArrayRows(); i++)
            l_Name = CString(l_ArrayName);
    l_Statement->closeResultSet(l_ResultSet);
    m_Connection->terminateStatement(l_Statement);
    catch (SQLException &p_SQLException)
    I hope that sample help you.
    Regards                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Ora-01001 in procedures with ref cursor parameter after upgrade to 11.1.0.7

    Hi,
    after upgrading from 11.1.0.6.0 to 11.1.0.7.0, I get ora-01001 in procedure calls which have a ref cursor as an out parameter.
    Even a new 11.1.0.7 instance throws this error. My OS is Linux SLES10SP2.
    Please see atched sample code:
    CREATE OR REPLACE PACKAGE test1_pck
    IS
    PROCEDURE run1; -- OK on 11.1.0.6; fails on 11.1.0.7
    PROCEDURE run2; -- OK on 11.1.0.6; OK on 11.1.0.7
    END test1_pck;
    CREATE OR REPLACE PACKAGE BODY test1_pck
    IS
    TYPE t_rec IS RECORD(col dual.dummy%TYPE);
    TYPE t_cur IS REF CURSOR RETURN t_rec;
    PROCEDURE foo1(p_cur OUT t_cur)
    IS
    v_sql VARCHAR2(255) := 'BEGIN OPEN :1 FOR SELECT dummy FROM dual; END;';
    BEGIN
    EXECUTE IMMEDIATE v_sql USING p_cur;
    END foo1;
    PROCEDURE foo2
    IS
    v_sql VARCHAR2(255) := 'BEGIN OPEN :1 FOR SELECT dummy FROM dual; END;';
    v_cur t_cur;
    v_rec t_rec;
    BEGIN
    EXECUTE IMMEDIATE v_sql USING v_cur;
    LOOP
    FETCH v_cur INTO v_rec;
    EXIT WHEN v_cur%NOTFOUND;
    CASE v_rec.col
    WHEN 'X' THEN dbms_output.put_line('success');
    ELSE dbms_output.put_line('error');
    END CASE;
    END LOOP;
    END foo2;
    PROCEDURE run1
    IS
    v_cur t_cur;
    v_rec t_rec;
    BEGIN
    foo1(v_cur);
    LOOP
    FETCH v_cur INTO v_rec;
    EXIT WHEN v_cur%NOTFOUND;
    CASE v_rec.col
    WHEN 'X' THEN dbms_output.put_line('success');
    ELSE dbms_output.put_line('error');
    END CASE;
    END LOOP;
    END run1;
    PROCEDURE run2
    IS
    BEGIN
    foo2;
    END run2;
    END test1_pck;
    Thanks for any hints.
    Regards Frank

    Hi Max,
    the referenced thread discusses a .Net problem. A lot of layers are involved their. My problem is a very basic problem. You get this error even if you run the test in a sql session on the server.
    It would be a great help for me
    a) if someone could test this package on a 11.1.0.7 database
    b) if someone could test this package on a 11.2 database (is it fixed in Release2?)
    c) if someone could give me hints how I could modify the procedure to make it usable for 11.1.0.7
    (I already tried a lot e.g. EXECUTE IMMEDIATE v_sql USING OUT p_cur;
    Thank you
    Frank

  • Cursor as parameter

    How I can paste cursor as parameter?
    I am trying to paste cursor variable1 as a parameter in cursor variable2, but I'm getting error: PLS-00488: invalid variable declaration: object 'VARIABLE1' must be a type or subtype.
    This is the code:
    DECLARE
    CURSOR variable1 IS SELECT DEPARTMENT_ID from EMPLOyees;
    CURSOR variable2 (vvar variable1) IS SELECT FIRST_NAME,LAST_NAME from EMPLOyees where DEPARTMENT_ID=vvar;
    BEGIN
    OPEN variable1;
    for j in variable1 loop
    OPEN variable2 (j.DEPARTMENT_ID);
    for i in variable2 loop
    dbms_output.put_line(i.First_name ||' '||i.LAST_NAME);
    END loop;
    END loop;
    end;

    Buga wrote:
    This si what you need.
    What you are doing is not correct.And what you are showing in your code is also wrong.
    Why are you manually coding a nested loop join in PL/SQL. Why are you not using SQL and have it doing the join instead?
    PL/SQL is slower than SQL when it comes to processing SQL data.
    There is a very basic rule that describes this:
    Maximize SQL. Minimize PL/SQL+
    In other words, do not reinvent the wheel using PL/SQL - use SQL to its full capabilities. That ensures performance and scalability.

  • Cast error message when discovering ref cursor parameter from stored proced

    We are today using Microsoft's Oracle provider with some code from the old Data Application Block (from MSDN) to discover parameters from the stored procedures. This code uses the OracleCommandBuilder.DeriveParameters to get the parameters from the stored procedure and command.Parameters.CopyTo copies the discovered parameters into the command object.
    If I test with a simple function returning a ref cursor I get one parameter with type refCursor and ParameterDirection.OutPut. This is working fine as long we where using Microsoft's Oracle provider. But using Oracle ODP .NET I get the following error message on datadapter.Fill (I fill a dataset with the result from the reference cursor)
    Unable to cast object of Type 'Oracle.DataAccess.Client.OracleDataReader' to type 'Oracle.DataAccess.Types.OracleRefCursor.
    If I create a ref parameter manualy like this:
    OracleParameter myrefCursor = new OracleParameter();
    myrefCursor .OracleDbType = OracleDbType.RefCursor;
    myrefCursor .ParameterName = "myParameterName";
    myrefCursor .Direction = ParameterDirection.ReturnValue;
    and add it to the command object this is working OK. So it seems to be a problem with discovering ref cursor parameters from the database, other parameter types is OK.. I have compared the properties of my manual ref cursor parameter with the one discovered from the stored procedure, but I cannot see any difference. (I see the Value property has some values for the discovered one, but I have set this to DBNull.Value without any result)
    Any ideas why I get this error code? Is there any other code blocks I can use to discover the parameters? We send in params object[] with the different values into the helper class and the value is added to the parameter. (Se I don't need to set the data type etc for each parameter, I just need to have the correct order of the parameters)

    For accuracy's sake, just wanted to let everyone know that this is actually a bug. The correct bug number is 8423178.
    Christian
    Mark_Williams wrote:
    Just to follow-up on this issue...
    The bug has been closed as "not a bug" as it seems undocumented behavior was relied upon for this to work in earlier releases.
    Note from the documentation on DeriveParameters:
    "The output values of derived parameters return as .NET Types by default. To obtain output parameters as provider types, the OracleDbType property of the parameter must be set explicitly by the application to override this default behavior. One quick way to do this is to set the OracleDbType to itself for all output parameters that should be returned as provider types." (emphasis added)
    The issue, as you might already know, is that there is no corresponding .NET Framework Type for an Oracle Ref Cursor and the type is, therefore, set to Object. So, explicitly setting the type to OracleDbType.RefCursor should work.
    Regards,
    Mark

  • How to open a Ref cursor in Oracle Reports

    I have a stored procedure that returns a ref cursor as an output parameter. I want to call this stored procedure in Oracle Reports After Form trigger. I am having trouble with the syntax of the output parameter. Event_record is the name of the cursor.
    After Form Trigger
    pkg_DEAL_WHITESHEET_CONCERTS.prc_Event_Information(:p_field_6,event_record);
    Error: Event_record must be declared

    Re-Write the procedure as Package Spec and Body. Declare the REFCursor in the Package Spec. Probably that helps.

  • Passing in values to a cursor in a package procedure

    Hi all
    I have a package :- test
    i have a procedure in the package :- test_proc
    in the procedure i have a cursor
    which has a select statement
    select jobid,jobname from jobs
    where jobcode = p_job_code; -- i think this is wrong
    when i execute the package i pass the job code to the package as a parameter which i use in the cursor above
    as a parameter i have values(i can select any of the above values )
    job code :-
    10
    20
    10,20
    how can i pass the values to the cursor in the procedure
    it is giving me invaiid number;

    Dear abcdxyz!
    As already stated you should try this with dynamic SQL. Here is an example for you:
    CREATE OR REPLACE PROCEDURE job_cursor(p_job_code VARCHAR2)
    IS
      l_jobid      NUMBER(5);
      l_jobname    VARCHAR2(30);
      c_job_cursor INTEGER;
      l_ignore     INTEGER;
    BEGIN
      -- open cursor on source table
      c_job_cursor := DBMS_SQL.Open_Cursor;
      -- parse the SELECT statement
      DBMS_SQL.parse(c_job_cursor, 'SELECT jobid, jobname FROM job WHERE job_code IN (' || p_job_code || ')', DBMS_SQL.NATIVE);
      -- define the column type
      DBMS_SQL.Define_Column(c_job_cursor, 1, l_jobid);
      DBMS_SQL.Define_Column(c_job_cursor, 2, l_jobname, 30);
      ignore := DBMS_SQL.Execute(c_job_cursor);
      LOOP
      -- Fetch a row from the source table
        IF DBMS_SQL.Fetch_Rows(c_job_cursor) > 0 THEN
            -- get column values of the row
            DBMS_SQL.Column_Value(c_job_cursor, 1, l_jobid);
            DBMS_SQL.Column_Value(c_job_cursor, 2, l_jobname);
        ELSE
           -- No more rows to copy
          EXIT;
        END IF;
      END LOOP;
      DBMS_OUTPUT.PUT_LINE(l_jobid || ', ' || l_jobname);
      DBMS_SQL.Close_Cursor(c_job_cursor);
    EXCEPTION
      WHEN OTHERS THEN
        IF DBMS_SQL.Is_Open(c_job_cursor) THEN
          DBMS_SQL.Close_Cursor(c_job_cursor);
        END IF;
        RAISE;
    END;
    /Yours sincerely
    Florian W.
    P.S. I haven't tested this procedure.

  • Table name as parameter to function

    Hi all,
    can anybody help me on the below issue..
    i have a function like this:
    **create or replace**
    **function "IL_SUM_AVG_FN" return number is**
    **cursor c1 is**
    **     select     sum_avg_val value**
    **     from     wel_10_tab**
    **     where     type='1';**
    **v_sum number;**
    **v_count number;**
    **BEGIN**
    **     v_sum:=0;**
    **     v_count:=0;**
    **     for i in c1 loop**
    **          if v_count=0 then**
    **               v_sum:=i.value;**
    **          else**
    **               v_sum:=abs(i.value+v_sum);**
    **          end if;**
    **          v_count:=v_count+1;**
    **     end loop;**
    **     return v_sum;**
    **END;**
    now my requirement is like..i want to pass a value as parameter to the function..say i will pass 10 or11 or 12
    then it should change the table name in the cursor according to the parameter.i.e
    if the parameter is 10 it should be: select sum_avg_val value from wel_10_tab where type='1';
    if the parameter is 11 it should be: select sum_avg_val value from wel_11_tab where type='1';
    if the parameter is 12 it should be: select sum_avg_val value from wel_12_tab where type='1';
    parameter has only these three possible values..
    how to achieve this?
    please help..

    Hi,
    you can do without execute immediate and one cursor is sufficient, if you use open cursor for ...:
    set serveroutput on;
    drop table TestTab1;
    drop table TestTab2;
    create table TestTab1 (
         val number
    create table TestTab2 as (select * from TestTab1 where 0 = 1);
    create or replace procedure TestProc (
         TableName in varchar2)
    is
         rec TestTab1%rowtype;
         cur sys_refcursor;
         curStr varchar2(1024) := 'select * from ' || TableName;
    begin
         open cur for curStr;
         loop
              fetch cur into rec;
              exit when cur%notfound;
              dbms_output.put_line ('value = ' || rec.val);
         end loop;
    end;
    insert into TestTab1 (val) values (1);
    insert into TestTab1 (val) values (2);
    insert into TestTab1 (val) values (3);
    insert into TestTab1 (val) values (4);
    insert into TestTab2 (val) values (101);
    insert into TestTab2 (val) values (102);
    insert into TestTab2 (val) values (103);
    insert into TestTab2 (val) values (104);
    begin TestProc('TestTab1'); end;
    begin TestProc('TestTab2'); end;
    /regards,
    Frank
    Edited by: user8704911 on Jul 11, 2011 10:35 PM
    Edited by: user8704911 on Jul 11, 2011 10:36 PM

  • Error calling a  stored procedure returning a PLSQL table /  REF cursor

    stored proceure declares -
    TYPE A_rec IS RECORD (
    date DATE,
    id NUMBER(10),
    start NUMBER (10),
    end NUMBER (10)
    TYPE tmp_tbl IS TABLE OF A_rec ;
    PROCEDURE get_B(
    p_id IN NUMBER,
    p_startdate IN DATE,
    p_enddate IN DATE,
    p_tbl OUT tmp_tbl
    My Java code reads -
    StoredProcedureCall storedProcedureCall = new StoredProcedureCall();
    storedProcedureCall.setProcedureName("get_B");
    DataReadQuery query = new DataReadQuery();
    query.setCall(storedProcedureCall);
    Vector parameters = new Vector();
    /** For all input params **/
    query.addArgument(param.getInputParamName(" name");
    parameters.add("values");
    /** Now comes the OUT part .. i am not sure what to do **/
    storedProcedureCall.useNamedCursorOutputAsResultSet("p_tbl ");
    /** execute query **/
    Vector result = (Vector) getSession(ctx).executeQuery(query, parameters);
    ------------- My program does not throw any error ... but does not return anything ----

    TopLink currently doesn't support pl/sql types to be used as stored procedures parameters - but version 11 will.
    However you can use a single cursor as an out parameter in your stored procedure:
    p_tbl OUT CURSOR_TYPE.ANY_CURSOR,
    and it will be returned by TopLink.

Maybe you are looking for

  • Excise Duties are not appearing in GR

    Hi Experts, User has created a Scheduling agreement and maintained Excise conditions in Agreement. When he tried to do Goods receipt,he is not able to see Excise tab in Goods receipt.What would be the reason for this? Please anyone can tell me.... Th

  • How can i create a native procedure??

    Hi all, How can i create a native procedure in Oracle 8.1.7??? P.S.: Without using OCI. thanx.

  • Blue tint

    hi there i have a dv7-7332ea and i noticed after comparing images with my partners hp desktop that the screen has a blue tint just slight but when trying to edit photos it makes a huge difference , i looked at the monitor settings in control pannel a

  • N-to-Embedded-Many Mapping ?

    Is a Mapping like the following possible with kodo ?: class A { HashMap members; // key=Integer, value= Instance of classB class B { int valueA; int valueB; tables: CLASSA_TABLE      JDOID: BIGINT CLASSA_MEMBERS_TABLE      JDOID: BIGINT      CLASSA_J

  • Materialized view excessive logging.  SOS

    The refresh of our materialized view is causing excessive logging. I altered the materialized view to NOLOGGING but it did not have any effect, not sure why? We either need to change the refresh time from 3 minutes to every 15 minutes(which is a bumm