Ref Cursor as an out parameter.

Hi all
Please help me with this.

It is a small procedure where the ref cursor is used as output parameter.
create or replace
PROCEDURE P_REFCURSOR_OUT 
(P_DEPTNO    IN  EMP.DEPTNO%TYPE,
P_RECORDSET OUT SYS_REFCURSOR) AS 
BEGIN 
      OPEN P_RECORDSET FOR
      SELECT EMPNO,
      EMPNM,
      DEPTNO
      FROM   EMP
      WHERE  DEPTNO = P_DEPTNO
      ORDER BY EMPNM;
END P_REFCURSOR_OUT;
There is another procedure that calls the procedure above. But during the call, it is throwing an exception that ORA-01722. What's not here? Help, please.
CREATE OR REPLACE PROCEDURE P_CALL_REFCURSOR_OUT AS
  L_CURSOR  SYS_REFCURSOR;
  L_EMPNM   EMP.EMPNM%TYPE;
  L_EMPNO   EMP.EMPNO%TYPE;
  L_DEPTNO  EMP.DEPTNO%TYPE;
BEGIN
  P_REFCURSOR_OUT (P_DEPTNO    => 1000,
              P_RECORDSET => L_CURSOR);
            
  LOOP 
    FETCH L_CURSOR
    INTO  L_EMPNM, L_EMPNO, L_DEPTNO;
    EXIT WHEN L_CURSOR%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(L_EMPNM || ' | ' || L_EMPNO || ' | ' || L_DEPTNO);
  END LOOP;
  CLOSE L_CURSOR;
END P_CALL_REFCURSOR_OUT;
Kind regards
BS2012

The cursor that you open selects the EMPNO and DEPTNO EMPNM in that order.
When you retrieve the cursor, you get in L_EMPNM, L_EMPNO, L_DEPTNO.

It would seem that the first two columns have been inverted in your FETCH statement. Assuming that EMPNO is a NUMBER EMPNM is a VARCHAR2, this means Oracle trying implicitly converted to the EMPNM in a NUMBER that is causing the error.

If you change the order of the variables in your FETCH statement, the error should disappear

    FETCH L_CURSOR
    INTO   L_EMPNO, L_EMPNM, L_DEPTNO;

Justin

Tags: Database

Similar Questions

  • PL/SQL - Call Out Ref Cursor returned by a stored procedure

    Hello

    I am creating a procedure where a Ref Cursor is defined as an OUT parameter, my question is how to shout that the Ref Cursor when I run for example here is how I want to call my EXEC sql command:

    EXEC film_not_in_stock (2,2,vcur);

    Here is the procedure:

    CREATE OR REPLACE PROCEDURE film_not_in_stock (p_film_id in NUMBER, p_store_id number, vcur ON SYS_REFCURSOR)

    IS

    News sys_refcursor;

    v_cur inventory.inventory_id%TYPE--ou is the same type of column inventory_id

    v_cur sys_refcursor;

    BEGIN

    Heart OPEN to SELECT inventory_id

    INVENTORY

    WHERE film_id = p_film_id

    AND store_id = p_store_id

    AND inventory_id NOT IN (SELECT inventory_in_stock (inventory_id) FROM dual);

    News of FETCH in v_cur;

    OUTPUT WHEN heart % NOTFOUND;

    END;

    /

    I know there are typos in the procedure, you will appreciate if you can help me to put it right.

    Thank you very much!

    Tonya.

    In fact, based on your previous post, function inventory_in_stock returns 0 or 1. If so, there are:

    CREATE OR REPLACE

    PROCEDURE film_not_in_stock)

    p_film_id in NUMBERS

    p_store_id in NUMBERS

    p_cur ON SYS_REFCURSOR

    )

    IS

    News sys_refcursor;

    v_cur inventory.inventory_id%TYPE--ou is the same type of column inventory_id

    v_cur sys_refcursor;

    BEGIN

    OPEN p_cur

    FOR

    SELECT inventory_id

    INVENTORY

    WHERE film_id = p_film_id

    AND store_id = p_store_id

    AND inventory_in_stock (inventory_id) = 0;

    News of FETCH in v_cur;

    OUTPUT WHEN heart % NOTFOUND;

    END;

    /

    SY.

  • How to call a stored procedure with a REF CURSOR output parameter

    I'm looking forward to example calling a function/stored procedure with a REF CURSOR output parameter and get the result.
    In other words, I have a stored function/procedure that runs a SELECT statement using the OCI library and then he could get the values of each row and each column.

    I put a code snippet, it have only the main thing to call a simple stored procedure and to print the name of each column of the cursor, but I couldn t to print out values in the table that calls the stored procedure.
    I understand that the next step is to call an OCIStmtFetch.
    How to associate the slider with the OCIStmtFetch?

    If you need more information, just tell me.

    I use ANSI C with HP - UX (HP - UX C) operating system and Oracle 10 g.


    Kind regards.

    Antonio Garcia


    / * callOracleSP * /.

    #include < stdio.h >
    #include < string.h >
    #include < oci.h >
    #include < stdlib.h > to

    char * pConnectChar = "Server";
    char * pUsernameChar = "user";
    char * pPasswordChar = "passwd";
    char * sqlCharArray1 = "BEGIN SP_GETCITIES (:,: c); END; « ;
    int retval;
    UB4 parmcnt = 0;
    UB4 pos2 = 0;
    text * pcoln [20];
    UB4 namelen [20];
    char state_key [5];

    OCIStmt * pOciStatement;
    OCIStmt * pOciStatCursor;
    OCIError * pOciError;
    OCIEnv * pOciEnviron;
    OCIServer * pOciServer;
    OCISession * pOciSession;
    OCISvcCtx * pOciServiceContext;
    OCIBind * pOciBind [500];
    OCIParam * pOciParam;


    int main()
    {
    retval = OCIEnvCreate (& pOciEnviron, OCI_DEFAULT, NULL, NULL, NULL, NULL, 0, NULL);
    retval = OCIEnvInit (& pOciEnviron, OCI_DEFAULT, 0, NULL);
    retval = OCIHandleAlloc (pOciEnviron, (void *) & pOciError, OCI_HTYPE_ERROR, 0, NULL);
    retval = OCIHandleAlloc (pOciEnviron, (void *) & pOciServiceContext, OCI_HTYPE_SVCCTX, 0, NULL);
    retval = OCIHandleAlloc (pOciEnviron, (void *) & pOciStatement, OCI_HTYPE_STMT, 0, NULL);

    retval = OCILogon (pOciEnviron, pOciError, & pOciServiceContext,(unsigned char *) pUsernameChar,
    strlen (pUsernameChar), (unsigned char *) pPasswordChar, strlen (pPasswordChar).
    (unsigned char *) pConnectChar, strlen (pConnectChar));
    printf ("retval=%d\n",retval OCILogon);

    retval = OCIStmtPrepare (pOciStatement, pOciError, (unsigned char *) sqlCharArray1, strlen (sqlCharArray1),)
    OCI_NTV_SYNTAX, OCI_DEFAULT);
    printf ("StmtPrepare retval=%d\n",retval);

    retval = OCIHandleAlloc (pOciEnviron, (void *) & pOciStatCursor, OCI_HTYPE_STMT, 0, NULL);
    retval = 1 OCIBindByPos(pOciStatement,&pOciBind[0], pOciError, (ub4), (void *) & state_key,)
    ((sb4) sizeof (state_key), SQLT_STR, (void *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT (ub4));
    printf ("BindByPos OCI_HTYPE_STMT retval=%d\n",retval);

    retval = OCIBindByPos(pOciStatement,&pOciBind[1], pOciError, (ub4) 2, (void *) & pOciStatCursor,)
    ((sb4) 0, SQLT_RSET, (void *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT (ub4));
    printf ("BindByPos OCI_HTYPE_STMT retval=%d\n",retval);

    strcpy (state_key, 'ca');

    retval = OCIStmtExecute (pOciServiceContext, pOciStatement, pOciError, (ub4) 1, (ub4) 0,)
    (OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_DEFAULT (ub4));
    printf ("StmtExecute retval=%d\n",retval);

    / * How to get the values of the cursor? */

    / * Number of parameters of the cursor * /.
    OCIAttrGet ((void *) pOciStatCursor, OCI_HTYPE_STMT (ub4), (void *) & parmcnt,(ub4 *) 0,)
    (ub4) (OCI_ATTR_PARAM_COUNT, pOciError);
    printf ("\nNumber of the slider settings = %d\n",parmcnt);

    for (int pos = 1; pos < = (int) parmcnt; pos ++)
    {
    OCIAttrGet ((void *) pOciStatCursor, OCI_HTYPE_STMT (ub4), (void *) & pos2,(ub4 *) 0,)
    (ub4) (OCI_ATTR_CURRENT_POSITION, pOciError);
    retval = OCIParamGet ((void *) pOciStatCursor, OCI_HTYPE_STMT (ub4), pOciError, (void *) & pOciParam,)
    POS (ub4));
    OCIAttrGet pOciParam, (ub4) ((void*) OCI_DTYPE_PARAM,(void*) & pcoln [pos - 1],(ub4 *) & namelen [pos-1],)
    (ub4) OCI_ATTR_NAME,(OCIError *) pOciError);
    }
    for (int i = 1; i < = (int) parmcnt; i ++)
    printf ("%i\tNAME = % column. ("* s\n", i, namelen [i-1], pcoln [i-1]);

    return 0;
    }


    This is the script that create the table, insert records and create the stored procedure

    CREATE TABLE CITIES)
    STATE_CODE VARCHAR2 (2) NULL,
    CITY_CODE NUMBER (15.5) NULL,
    CITY_NAME VARCHAR2 (30) NULL
    )
    /


    INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES ('CA', 30, 'SAN DIEGO')
    /
    INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES ('CA', 40 'SACRAMENTO')
    /
    INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES ('FL', 10, 'MIAMI')
    /
    INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES ('FL', 20, 'ORLANDO')
    /
    INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES ('NEW YORK', 10, 'NEW YORK')
    /
    INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES ('NEW YORK', 20, 'ALBANY')
    /
    INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES ('CA', 10, 'LOS ANGELES')
    /
    INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES ('CA', 20, 'SAN FRANCISCO')
    /


    CREATE or REPLACE PACKAGE globalPkg AUTHID CURRENT_USER AS
    / * The following is specific global variables T/SQL. */
    TYPE RCT1 IS REF CURSOR; / * new cursor low definition * /.
    END globalPkg;
    /



    CREATE OR REPLACE PROCEDURE SP_ADDCITY)
    P_STATE_CODE IN VARCHAR,
    P_CITY_CODE NUMBER,
    P_CITY_NAME IN VARCHAR2,
    P_RETURN IN NUMBERS)
    AS
    StoO_error INTEGER;
    StoO_selcnt INTEGER;
    StoO_rowcnt INTEGER;
    StoO_errmsg VARCHAR2 (255);

    BEGIN
    StoO_rowcnt: = 0;
    StoO_error: = 0;
    StoO_selcnt: = 0;
    P_RETURN: = 0;
    INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES (P_STATE_CODE, P_CITY_CODE, P_CITY_NAME);
    StoO_rowcnt: = number of LINES SQL %;
    EXCEPTION
    WHEN TOO_MANY_ROWS THEN
    StoO_rowcnt: = 2;
    WHILE OTHERS THEN
    StoO_rowcnt: = 0;
    StoO_selcnt: = 0;
    StoO_error: = SQLCODE;
    StoO_errmsg: = SQLERRM;
    IF StoO_error! = 0 THEN
    BEGIN
    P_RETURN: = 1;
    RETURN;
    END;
    END IF;
    END;
    /

    CREATE OR REPLACE PROCEDURE SP_GETCITIES)
    STATE_KEY IN VARCHAR,
    RC1 IN OUT globalPkg.RCT1)
    AS
    StoO_error INTEGER;
    StoO_selcnt INTEGER;
    StoO_rowcnt INTEGER;
    StoO_errmsg VARCHAR2 (255);
    BEGIN
    StoO_rowcnt: = 0;
    StoO_error: = 0;
    StoO_selcnt: = 0;
    OPEN FOR RC1
    SELECT STATE_CODE, CITY_CODE, FRANCISCO
    CITIES
    WHERE STATE_CODE = STATE_KEY
    ORDER BY CITY_CODE;
    StoO_rowcnt: = number of LINES SQL %;
    EXCEPTION
    WHILE OTHERS THEN
    StoO_rowcnt: = 0;
    StoO_error: = SQLCODE;
    StoO_errmsg: = SQLERRM;
    END;
    /

    Hi Antonio,.

    I see this:

    c_buf=(ub1 **)calloc(sizeof(ub1 *),3);
    
    ...
    
    rc=OCIDefineByPos(pOciStatCursor,&pdef,(OCIError *)pOciError,pos,c_buf[pos-1],size+1,(ub2)type,(dvoid *)c_indp[pos-1],(ub2 *)0,(ub2 *)0,OCI_DEFAULT);
    

    That I don't understand. You allocate space for 3 pointers ub1 but I don't see where these pointers are then initialized to point to where the data is to be stored.

    I do not read correctly?

    Sorry for posting code long, but here is an example of code that I have. It is much more 'code' for your code, but maybe that will be enough...

    NOTE: This is just the code example and not rigorous. For example, I don't check the memory, allocations etc in this code!

    Kind regards

    Mark

    #ifdef WIN32
    #define _CRT_SECURE_NO_DEPRECATE 1
    #endif
    
    #include 
    #include 
    #include 
    #include 
    
    void checkerr(sword status, OCIError *errhp);
    
    int main(int argc, char *argv[]) {
      OCIEnv      *envhp = NULL;  /* OCI Environment handle     */
      OCIError    *errhp = NULL;  /* OCI Error handle           */
      OCISvcCtx   *svchp = NULL;  /* OCI Service Context handle */
      OCIServer   *srvhp = NULL;  /* OCI Server handle          */
      OCISession  *usrhp = NULL;  /* OCI User Session handle    */
    
      OCIStmt     *stmtp = NULL;  /* OCI Statement handle       */
      OCIStmt     *cursr = NULL;  /* OCI Statement handle       */
    
      OCIParam    *prmp1 = NULL;  /* OCI Parameter handle       */
      OCIParam    *prmp2 = NULL;  /* OCI Parameter handle       */
      OCIParam    *prmp3 = NULL;  /* OCI Parameter handle       */
    
      OCIDefine   *defp1 = NULL;  /* OCI Define handle          */
      OCIDefine   *defp2 = NULL;  /* OCI Define handle          */
      OCIDefine   *defp3 = NULL;  /* OCI Define handle          */
    
      OCIBind     *bndp1 = NULL;  /* OCI Bind handle            */
      OCIBind     *bndp2 = NULL;  /* OCI Bind handle            */
      OCIBind     *bndp3 = NULL;  /* OCI Bind handle            */
    
      /* used to hold column width */
      ub2 col_width;
    
      /* used to set the prefetch count */
      ub4 prefetch_count = 32;
    
      /* will hold output from database */
      oratext *pEmpId = NULL;
      oratext *pFirstName = NULL;
      oratext *pLastName = NULL;
    
      /* the anonymous block to execute */
      /* this opens a ref cursor        */
      oratext *sqlstmt = "begin " \
                         "  open :1 for " \
                         "  select   to_char(employee_id), " \
                         "           first_name, " \
                         "           last_name " \
                         "  from     hr.employees " \
                         "  order by last_name, " \
                         "           first_name; " \
                         "end;";
    
      /* used to hold the results of each OCI call */
      sword result = 0;
    
      /* Initialize and create a default environment  */
      result = OCIEnvCreate(&envhp,
                            OCI_DEFAULT,
                            (dvoid *) 0,
                            0,
                            0,
                            0,
                            (size_t) 0,
                            (dvoid **) 0);
    
      /* allocate an error handle */
      result = OCIHandleAlloc((dvoid *) envhp,
                              (dvoid **) &errhp,
                              OCI_HTYPE_ERROR,
                              0,
                              (dvoid **) 0);
    
      /* allocate a service context handle */
      result = OCIHandleAlloc((dvoid *) envhp,
                              (dvoid **) &svchp,
                              OCI_HTYPE_SVCCTX,
                              0,
                              (dvoid **) 0);
    
      /* allocate a server handle */
      result = OCIHandleAlloc((dvoid *) envhp,
                              (dvoid **) &srvhp,
                              OCI_HTYPE_SERVER,
                              0,
                              (dvoid **) 0);
    
      /* allocate a user session handle */
      result = OCIHandleAlloc((dvoid *) envhp,
                              (dvoid **) &usrhp,
                              OCI_HTYPE_SESSION,
                              0,
                              (dvoid **) 0);
    
      /* create a server context using the "ORADEMO" database */
      result = OCIServerAttach(srvhp,
                               errhp,
                               "ORADEMO",
                               (ub4) strlen("ORADEMO"),
                               OCI_DEFAULT);
    
      /* set the server attribute in the service context handle */
      result = OCIAttrSet((dvoid *) svchp,
                          OCI_HTYPE_SVCCTX,
                          (dvoid *) srvhp,
                          (ub4) 0,
                          OCI_ATTR_SERVER,
                          errhp);
    
      /* open the session with the database */
      /* using external authentication      */
      result = OCISessionBegin(svchp,
                               errhp,
                               usrhp,
                               OCI_CRED_EXT,
                               OCI_DEFAULT);
    
      /* set the user session attribute in the service context handle */
      result = OCIAttrSet((dvoid *) svchp,
                          OCI_HTYPE_SVCCTX,
                          (dvoid *) usrhp,
                          (ub4) 0,
                          OCI_ATTR_SESSION,
                          errhp);
    
      /* allocate the statement handle */
      result = OCIHandleAlloc((dvoid *) envhp,
                              (dvoid **) &stmtp,
                              OCI_HTYPE_STMT,
                              0,
                              (dvoid **) 0);
    
      /* prepare the statement for execution */
      result = OCIStmtPrepare(stmtp,
                              errhp,
                              sqlstmt,
                              (ub4) strlen((char *) sqlstmt),
                              OCI_NTV_SYNTAX,
                              OCI_DEFAULT);
    
      /* allocate the handle for the ref cursor */
      result = OCIHandleAlloc((dvoid *) envhp,
                              (void **) &cursr,
                              OCI_HTYPE_STMT,
                              0,
                              NULL);
    
      /* bind the ref cursor parameter */
      result = OCIBindByPos(stmtp,
                            &bndp1,
                            errhp,
                            1,
                            &cursr,
                            0,
                            SQLT_RSET,
                            NULL,
                            0,
                            NULL,
                            0,
                            0,
                            OCI_DEFAULT);
    
      /* execute the statement */
      result = OCIStmtExecute(svchp,
                              stmtp,
                              errhp,
                              1,
                              0,
                              NULL,
                              NULL,
                              OCI_DEFAULT);  
    
      /* get parameter descriptor for first column */
      result = OCIParamGet((dvoid *) cursr,
                           OCI_HTYPE_STMT,
                           errhp,
                           (dvoid **) &prmp1,
                           (ub4) 1);
    
      /* get parameter descriptor for second column */
      result = OCIParamGet((dvoid *) cursr,
                           OCI_HTYPE_STMT,
                           errhp,
                           (dvoid **) &prmp2,
                           (ub4) 2);
    
      /* get parameter descriptor for third column */
      result = OCIParamGet((dvoid *) cursr,
                           OCI_HTYPE_STMT,
                           errhp,
                           (dvoid **) &prmp3,
                           (ub4) 3);
    
      /* get the first column width in characters */
      result = OCIAttrGet((dvoid*) prmp1,
                          (ub4) OCI_DTYPE_PARAM,
                          (dvoid*) &col_width,
                          (ub4 *) 0,
                          (ub4) OCI_ATTR_DATA_SIZE,
                          errhp);
    
      /* allocate memory to hold the result */
      pEmpId = (oratext *) malloc(sizeof(oratext) * (col_width + 1));
    
      /* define the first column in the results */
      result = OCIDefineByPos(cursr,
                              &defp1,
                              errhp,
                              1,
                              (dvoid *) pEmpId,
                              (sword) col_width + 1,
                              SQLT_STR,
                              (dvoid *) NULL,
                              (ub2 *) 0,
                              (ub2 *) 0,
                              OCI_DEFAULT);
    
      /* get the second column width in characters */
      result = OCIAttrGet((dvoid*) prmp2,
                          (ub4) OCI_DTYPE_PARAM,
                          (dvoid*) &col_width,
                          (ub4 *) 0,
                          (ub4) OCI_ATTR_DATA_SIZE,
                          errhp);
    
      /* allocate memory to hold the result */
      pFirstName = (oratext *) malloc(sizeof(oratext) * (col_width + 1));
    
      /* define the second column in the results */
      result = OCIDefineByPos(cursr,
                              &defp2,
                              errhp,
                              2,
                              (dvoid *) pFirstName,
                              (sword) col_width + 1,
                              SQLT_STR,
                              (dvoid *) NULL,
                              (ub2 *) 0,
                              (ub2 *) 0,
                              OCI_DEFAULT);
    
      /* get the third column width in characters */
      result = OCIAttrGet((dvoid*) prmp3,
                          (ub4) OCI_DTYPE_PARAM,
                          (dvoid*) &col_width,
                          (ub4 *) 0,
                          (ub4) OCI_ATTR_DATA_SIZE,
                          errhp);
    
      /* allocate memory to hold the result */
      pLastName = (oratext *) malloc(sizeof(oratext) * (col_width + 1));
    
      /* define the third column in the results */
      result = OCIDefineByPos(cursr,
                              &defp3,
                              errhp,
                              3,
                              (dvoid *) pLastName,
                              (sword) col_width + 1,
                              SQLT_STR,
                              (dvoid *) NULL,
                              (ub2 *) 0,
                              (ub2 *) 0,
                              OCI_DEFAULT);
    
      /* loop through and print the results */
      while ((result = OCIStmtFetch(cursr,
                                    errhp,
                                    (ub4) 1,
                                    (ub2) OCI_FETCH_NEXT,
                                    (ub4) OCI_DEFAULT)) == OCI_SUCCESS)
      {
        printf("Employee ID: %s\n", pEmpId);
        printf(" First Name: %s\n", pFirstName);
        printf("  Last Name: %s\n\n", pLastName);
      }
    
      /* free allocated memory */
      free(pEmpId);
      free(pFirstName);
      free(pLastName);
    
      pEmpId = NULL;
      pFirstName = NULL;
      pLastName = NULL;
    
      /* terminate the session with the database */
      result = OCISessionEnd(svchp, errhp, usrhp, OCI_DEFAULT);
    
      /* detach from the server */
      result = OCIServerDetach(srvhp, errhp, OCI_DEFAULT);
    
      /* deallocate the environment handle     */
      /* OCI will deallocate the child handles */
      result = OCIHandleFree((dvoid *) envhp, OCI_HTYPE_ENV);
    
      return OCI_SUCCESS;
    }
    
    void checkerr(sword status, OCIError *errhp)
    {
      oratext errbuf[512];
      sb4 errcode = 0;
    
      switch (status) {
        case OCI_SUCCESS:
          break;
    
        case OCI_ERROR:
        case OCI_SUCCESS_WITH_INFO:
          (void) OCIErrorGet((dvoid *) errhp, (ub4) 1, (oratext *) NULL, &errcode, errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
          (void) printf("Error: %.*s\n", sizeof(errbuf), errbuf);
          break;
    
        case OCI_NEED_DATA:
          (void) printf("Error - OCI_NEED_DATA\n");
          break;
    
        case OCI_NO_DATA:
          (void) printf("Error - OCI_NO_DATA\n");
          break;
    
        case OCI_INVALID_HANDLE:
          (void) printf("Error - OCI_INVALID_HANDLE\n");
          break;
    
        case OCI_STILL_EXECUTING:
          (void) printf("Error - OCI_STILL_EXECUTING\n");
          break;
    
        case OCI_CONTINUE:
          (void) printf("Error - OCI_CONTINUE\n");
          break;
    
        default:
          break;
      }
    }
    
  • How to start the view off of the ref cursor Oracle as input/output param

    Hello world

    We use JDev 11.1.2.3 WL 10.3.6 and Java 7.

    We are at the beginning of our transition from Oracle Forms to ADF.  We have a very large forms that uses many store procedures that have IN/OUT ref Cursor parameters and tables plsql.  I tried to find information on best practices to achieve, but only seemed to find tutorials on SEO of the Oracle ref Cursor return functions.  I hope we don't have to rewrite our code of database to work with ADF.

    This is an example of a proc currently a block on a form based on directly

    The ref cursor parameter is input/output to satisfy the way the form handles this type of paradigm.

    ADF we want I hope to reuse these procs existing (without the need to wrap/overload them) on the basis of the display objects.

    Example:

    / * my record type which houses the information I want to go back * /.

    TYPE rec_hist_vacpac_status IS RECORD)

    rec_order NUMBER (5),

    rec_rownum NUMBER (5),

    return_column SAM_VACPAC.vacpac_status%TYPE,

    rec_login_id SAM_VACPAC.ins_user%TYPE,

    status_date SAM_VACPAC.status_date%TYPE

    );

    / * Sets the ref cursor type * /.

    TYPE lcur_hist_vacpac_status IS REF CURSOR;

    / * This is a procedure that would take some info link go / return

    Return the ref cursor of this information as an in / out * /.

    PROCEDURE prc_myinfo_refcur)

    pnum_identify_seq_id in NUMBERS

    pcur_myinfo IN OUT lcur_hist_vacpac_status);

    Can anyone point me in the right direction on documentation on this?

    Thank you!

    Hi Cemerson:

    See this example:

    1. 1. create a TYPE as an object

    CREATE OR REPLACE

    TYPE GOTYOB_EQUI

    AS AN OBJECT

    (

    CDELEM VARCHAR2 (50).

    TIELEM VARCHAR2 (2)

    );

    1. 2. create a TABLE TYPE AS

    CREATE OR REPLACE

    TYPE GOTYTA_EQUI

    AS THE GOTYOB_EQUI TABLE;

    1. 3 create a function, it returns the TYPE of the TABLE

    FUNCTION fn_equiposarriba)

    pa_cdelem IN VARCHAR2,

    pa_nucomp in NUMBERS

    pa_anperi in NUMBERS

    pa_meperi in NUMBERS

    )

    Gotyta_equi RETURN PIPELINED IS

    CURSOR trae_equimani (va_cdelem VARCHAR2) IS

    SELECT cdelem, tielem, cdelempadr,

    (SELECT cdequi

    Of evm_alim

    WHERE anperi = eq.anperi

    AND meperi = eq.meperi

    AND nucomp = eq.nucomp

    AND cdalim = eq.cdalim) cdalim

    Of evm_equimani eq

    WHERE anperi = pa_anperi

    AND meperi = pa_meperi

    AND nucomp = pa_nucomp

    AND cdelem = va_cdelem

    AND cdelempadr <> cdelem

    AND tielem <> 'A ';

    equimani trae_equimani % ROWTYPE;

    va_cdalim VARCHAR2 (100);

    BEGIN

    -Loading los equipos aguas arriba

    WHILE equimani.cdelempadr IS NOT NULL LOOP

    OPEN trae_equimani (equimani.cdelempadr);

    equimani: = NULL;

    SEEK trae_equimani INTO equimani;

    CLOSE Trae_equimani;

    IF equimani.cdelem IS NOT NULL THEN

    PIPE ROW (gotyob_equi (equimani.cdelem, equimani.tielem));

    END IF;

    END LOOP;

    RETURN;

    END;

    1. 4 SQL Query with the help of the function... you can use this SQL in a display object

    SELECT

    *

    Of

    TABLE (gopq_eventos.fn_equiposarriba (' F-SCZ-043-103', '))

    1,

    2013,

    6

    )

    )

    Best regards, Marcelo

  • Packages and poorly Ref Cursor

    SQL Server Developer, I fight with Oracle to say the least. I fought with the poor performance of the extraction of data from the database, but also a multitude of other things. The last number I have is a stored procedure in a package that does not work when run from my .NET code. I have many other packages and stored procedures that are working, but this one is a failure. I don't get any errors, just no data when I should be.

    I would run the toad package and see if it is the stored Proc and packaging, or if there is a problem in my .NET code. My stored procedure accepts a single PARAMETER of type integer, and has two parameters SYS_RefCursor OUT. My SQL uses the parameter (ID field) to select from a table. If I run the select SQL by itself with the hardcoded value ID, it works fine. I can run too where it uses the SQL for open cursors and inserts the data but I can't determine if it worked.

    So, my questions are the following:

    Can I select a Ref_Cursor? I'm trying to do something like that.
    results_cursor SYS_REFCURSOR;
    
    OPEN results_cursor FOR
       SELECT * FROM Person;
    
    SELECT * FROM results_cursor;
    If I could get the 1st issue a response, I can keep up with my next question.

    Thanks in advance.
    Jeff

    Hello

    I don't see an issue of .NET at this point, so you can have the best chance to post in the forum PLSQL, as it seems that if you need help writing a procedure, rather than interacting with a procedure well known in .NET:
    SQL and PL/SQL

    I'm not clear on your question though. Yes, you can read from a slider ref, and you do it by getting him.

    SQL > set serveroutput on

    SQL > declare
    Ref1 2 sys_refcursor;
    3 rec1 emp % rowtype;
    Number 4 NTC;
    5. start
    6. open ref1 for select * from emp;
    7 LOOP
    8 FETCH INTO rec1 ref1;
    9 OUTPUT WHEN ref1% NOTFOUND;
    10 DBMS_OUTPUT. Put_line (' name = ' | rec1.ename);
    11 END OF LOOP;
    12 end;
    13.
    Name = SMITH
    Name = ALLEN
    Name = WARD
    Name = JONES
    Name = MARTIN
    Name = BLAKE
    Name = CLARK
    Name = SCOTT
    Name = KING
    Name = TURNER
    Name = ADAMS
    Name = JAMES
    Name = FORD
    Name = MILLER

    PL/SQL procedure successfully completed.

    SQL >

    Maybe if clarify what you are trying to do or accomplish in "selecting from a ref cursor" it would be useful.

    Greg

  • 'OUT' parameter is declared but never used

    Hello
    I created a package.that is given below.

    CREATE OR REPLACE PACKAGE Pkg_Sam_Ref_Cursr
    IS
    TYPE pa_sam_details_recrd IS RECORD (EMPNO number 4);
    TYPE pa_sam_details_cursr IS REF CURSOR RETURN pa_sam_details_recrd;
    END;

    and I created a function.that is given below

    CREATE OR REPLACE FUNCTION FunSam_Report)
    p_empno NUMBER
    )
    RETURN Pkg_Sam_Ref_Cursr.pa_sam_details_cursr
    IS
    data_cursr Pkg_Sam_Ref_Cursr.pa_sam_details_cursr;
    BEGIN
    Data_cursr OPEN to select A.* from Emp A where A.Empno = A.Deptno order p_empno;

    RETURN DATA_CURSR;
    END;

    and created a stored procedure.that is given below

    CREATE or replace PROCEDURE SP_SampleSP)
    P_EMPNO NUMBER,
    OUT Pkg_Sam_Ref_Cursr.pa_sam_details_cursr) IS data_cursr Pkg_Sam_Ref_Cursr.pa_sam_details_cursr;
    BEGIN
    data_cursr: = FunSam_Report (P_EMPNO);
    END;

    at compile time it will throw the following error but sp is created and how to see the result.

    Error: Hint: 'OUT' parameter is declared but never used in "SP_SampleSP".
    Line: 3
    Text: OUT Pkg_Sam_Ref_Cursr.pa_sam_details_cursr) IS data_cursr Pkg_Sam_Ref_Cursr.pa_sam_details_cursr;

    Error: Hint: value of 'data_cursr' in 'SP_SampleSP' never used
    Line: 5
    Text: data_cursr: = FunSam_Report (P_EMPNO);
    CREATE or replace PROCEDURE SP_SampleSP (
           P_EMPNO IN NUMBER,
           data_cursr OUT Pkg_Sam_Ref_Cursr.pa_sam_details_cursr)
    IS
    BEGIN
       data_cursr:= FunSam_Report(P_EMPNO);
    END;
    
  • using Ref cursor

    Hi all

    We have a defined as Ref Cursor.

    CREATE or REPLACE procedure Pspdetails_proc (supplier_id in varchar2, supplier_partno in varchar2)
    as
    type rc is REF CURSOR;
    l_cursor rc;

    l_query varchar2 (512)
    by default ' SELECT C2. N ° supplier, C2. SupplierPartNumber, Lon1.lse_Index, Lon1.lse_String
    C2PlantSpecificPricingTab C2, Lon1 LongStringElementTab
    WHERE C2.ls_Strings = Lon1.lvId AND C2.rootId = Lon1.rootId
    AND (C2. Active = 1) AND (C2. PurgeState = 0)';
    cursor l_template is SELECT C2. N ° supplier, C2. SupplierPartNumber, Lon1.lse_Index, Lon1.lse_String
    CVXPlantSpecificPricingTab C2, Lon1 LongStringElementTab
    WHERE C2.ls_Strings = Lon1.lvId AND C2.rootId = Lon1.rootId AND (C2. Active = 1) AND (C2. PurgeState = 0);

    l_rec l_template % rowtype;

    BEGIN
    If (supplier_id isn't supplier_partno NULL AND IS NOT NULL) then
    l_query: = l_query | "AND C2. SupplierID = "' | supplier_id | " ' AND C2. SUPPLIERPARTNUMBER = "' | supplier_partno | " ' ;
    end if;
    dbms_output. Put_line (l_query);
    Open the l_cursor for l_query;
    loop
    extract the l_cursor in l_rec;
    When the output l_cursor % notfound;
    dbms_output. Put_line (l_rec.lse_String);
    end loop;
    close l_cursor;
    end;
    /

    What should be the approach in case I want to return the value "l_rec.lse_String" of the piece of code above OR propose a different approach.

    Thank you very much in advance.

    What should be the approach in case I want to return the value "l_rec.lse_String" of the coin above the cod

    You can introduce an output parameter.
    In addition you don't need all this dynamic sql: a simplified version would be

    create or replace procedure pspdetails_proc (
       supplier_id       in     varchar2,
       supplier_partno   in     varchar2,
       lse_string           out varchar2)
    as
    begin
       if supplier_id is not null and supplier_partno is not null
       then
          select max (lon1.lse_string)
            into lse_string
            from c2plantspecificpricingtab c2, longstringelementtab lon1
           where     c2.ls_strings = lon1.lvid
                 and c2.rootid = lon1.rootid
                 and (c2.active = 1)
                 and (c2.purgestate = 0)
                 and c2.supplierid = supplier_id
                 and c2.supplierpartnumber = supplier_partno;
       else
          select max (lon1.lse_string)
            into lse_string
            from c2plantspecificpricingtab c2, longstringelementtab lon1
           where     c2.ls_strings = lon1.lvid
                 and c2.rootid = lon1.rootid
                 and c2.active = 1
                 and c2.purgestate = 0;
       end if;
    end pspdetails_proc;
    /
    
  • help how to extract the ref cursor in the table field

    Hello.


    I have a query similar to the following:
    select department_id, cursor (select employee_id from employees where department_id = d.department_id)
      from departments d
    Expecting to get several lines, I want this select this option to be in bulk sampled in a table variable nested (of another type of nested table) which is copied to an out parameter in a procedure. I have some doubts:
    1 should. what I create the column in the inner nested table that will keep the result of the ref cursor? Ref cursor colunm? A sort of column Adrien?
    2. If the column in the nested table inside that will keep the result of the ref cursor is another array, how can I write the result of the entire query in a single volume?

    (I want to bulk collect everything in a single query, I know how to do with pl/sql do not inflate but using two nested for loops, that's what I try to avoid).


    Thanks in advance.

    It would be simpler:

    declare
        type dep_emp_list_tbl_type
          is table of sys.OdciVarchar2List;
        v_dep_emp_list_tbl dep_emp_list_tbl_type;
        v_dep_id_tbl sys.OdciNumberList;
    begin
        select  department_id, cast(multiset(select employee_id from hr.employees where department_id = d.department_id) as sys.OdciVarchar2List)
          bulk collect into v_dep_id_tbl,v_dep_emp_list_tbl
          from hr.departments d;
    end;
    /
    

    SY.

  • Ref Cursor remote procedure fails

    Remote database server Oracle 9iR2 1

    Local database server Oracle 10 g 2 2

    Remote procedure:

    CREATE OR REPLACE PROCEDURE p_get_results (   i_query   IN   VARCHAR2
                                                , o_refc    OUT  sys_refcursor
                                              )
    AS
    BEGIN
        IF ( i_query IS NULL )
        THEN
             RAISE_APPLICATION_ERROR(-20001,'The paramter i_query cannot be null') ;
        END IF ;
    
    
        OPEN o_refc FOR i_query ;
        
        EXCEPTION
            WHEN   others   THEN
                 RAISE ;
    END p_get_results ;
    /
    
    

    Local PL/SQL block

    SQL> var i_query varchar2(100)
    SQL> var o_refc refcursor
    SQL> exec :i_query := 'select count(*) from oo_attrs'
    
    
    SQL> exec p_get_results@demo_oo2 (:i_query,:o_refc)
    
    
    ERROR at line 1:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-01001: invalid cursor
    
    

    Check the link works and request db:

    SQL> select count(*) from oo_attrs@demo_oo2;
    
      COUNT(*)
    ----------
           225
    

    Am I missing something here?

    Am I missing something here?

    Yes - you cannot use REF CURSOR over links to db.

  • 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

  • By the way the Ref cursor to the subprogrammes-taking islet of time to return

    Hello
    Version Oracle 11.2.0.1

    I test the way other Ref Cursor sub programs using examples of schema scott. Please see below for the code.
    create or replace package typ_ref_cursor_pkg
    as
    Type t_ref_cursor is REF CURSOR;
    end typ_ref_cursor_pkg;
    
    /
    
    
    create or replace package emp_info_pkg
    is
    Type rec_emp is record
      (
        name  emp.ename%TYPE,
        sal   emp.sal%Type
      );
    l_emp_rec rec_emp;
    Procedure get_emp_salary(p_cursor typ_ref_cursor_pkg.t_ref_cursor);
    Procedure get_emp_by_dept(p_deptno emp.deptno%type);
    end emp_info_pkg;
    /
    
    
    create or replace package body emp_info_pkg
    is
    Procedure get_emp_salary(p_cursor typ_ref_cursor_pkg.t_ref_cursor)
    is 
    begin 
    Loop
    Fetch p_cursor into l_emp_rec;
    exit when p_cursor%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(l_emp_rec.name||' - '||l_emp_rec.sal);
    end Loop;
    End get_emp_salary;
    
    Procedure get_emp_by_dept(p_deptno emp.deptno%type)
    is
    v_emp typ_ref_cursor_pkg.t_ref_cursor;
    Begin 
    open v_emp for select ename,sal from emp where deptno=p_deptno;
    LOOP
    get_emp_salary(v_emp);
    END LOOP;
    close v_emp;
    END get_emp_by_dept;
    END emp_info_pkg;
    /
    Everything compiled fine.while execution of the procedure taking a lot of time.
    execute emp_info_pkg.get_emp_by_dept(10);
    what I am doing wrong? Could you point me to the right direction?

    Thank you
    SG

    Sg049 wrote:
    Everything compiled fine.while execution of the procedure taking a lot of time.

    execute emp_info_pkg.get_emp_by_dept(10);
    

    How long is a long time? Is the code you have posted takes a lot of time, or is it just a case of quick test that works quickly?

    Start by checking the SQL code. Get an execution plan for SQL that you run and see if you do a scan of the complete table on the table - if so an index on deptno could help.

    I think you have an endless loop in get_emp_by_dept. I was unable to see a way out the manual of the WHILE loop.

  • Irregular data loss - function from PL/SQL returning data using Ref Cursor

    Database Version: 10.2.0.4.0 (node 2 CARS)

    The high-level process flow is as below:
    (1) insert records in a few tables & commit the same
    (2) call the pl/sql function to extract files (on certain conditions with joins with other tables) of the tables which are filled in step 1.
    -> It uses the ORDER BY clause to queries inline & line number 5000 records return for each call.
    Sense - if inline query is supposed to return 1,00,000 records then 20 calls to the same function. This, because the application cannot contain records beyond number.
    (3) the data returned by the ref cursor is then processed by application (Tibco BW) to generate the flat file.

    We are facing the problem of data loss in the file and there is no fixed model. It happens once between 200-300 calls process.
    Resolution: When the problem occurs, triggering the process and in almost every time re-outbreak of the process provides required data.

    Guidance on what could be the reason?

    * Examples of Code for the function:
    CREATE OR REPLACE FUNCTION FUNC_GET_HRCH_TOTAL_DATA)
    outinstrid in NUMBERS
    outinstrkey in NUMBERS
    rownumberstart in NUMBERS
    rownumbereend in NUMBERS
    err_code OUT VARCHAR2,
    err_msg OUT VARCHAR2)
    RETURN PACK_TYPES. HRCH_TOTAL_CURSOR
    IS
    REF_HRCH_TOTAL_CURSOR PACK_TYPES. HRCH_TOTAL_CURSOR;
    BEGIN

    OPEN FOR REF_HRCH_TOTAL_CURSOR
    SELECT *.
    FROM (SELECT A.HIERARCHY_KEY, B.KEY, B.VAL_KEY, A.KEY_NEW, C.ITEMID, B.VAL_TAG, B.sort_order, ROWNUM ROWNUMBER
    OF AOD_HRCH_ITEM A, AOD_HRCH_ATTR B, AOD_HRCH_ITEMS C
    WHERE A.outputid = B.outputid
    AND A.outputid = C.outputid AND A.outputkey = B.outputkey
    AND A.outputkey = C.outputkey AND A.outputid = outinstrid
    AND A.outputkey = outinstrkey AND A.ITEM_SEQ = B.ITEM_SEQ
    AND A.ITEM_SEQ = C.ITEM_SEQ AND A.HIERARCHY_LEVEL_ORDER = B.SORT_ORDER
    ORDER BY A.HIERARCHY_LEVEL_ORDER DESC)
    WHERE ROWNUMBER < rownumbereend
    AND ROWNUMBER > = rownumberstart;


    RETURN REF_HRCH_TOTAL_CURSOR;
    EXCEPTION
    WHILE OTHERS
    THEN
    err_code: = x_progress | ' - ' || SQLCODE;
    err_msg: = SUBSTR (SQLERRM, 1, 500);

    END FUNC_GET_HRCH_TOTAL_DATA;
    /

    Published by: meet_sanc on February 16, 2013 10:42

    Your SELECT statement is almost certainly incorrect

    SELECT *
      FROM ( SELECT A.HIERARCHY_KEY, B.KEY, B.VAL_KEY, A.KEY_NEW, C.ITEMID, B.VAL_TAG, B.sort_order,ROWNUM ROWNUMBER
               FROM AOD_HRCH_ITEM A, AOD_HRCH_ATTR B, AOD_HRCH_ITEMS C
              WHERE A.outputid = B.outputid
                AND A.outputid = C.outputid AND A.outputkey = B.outputkey
                AND A.outputkey = C.outputkey AND A.outputid = outinstrid
                AND A.outputkey = outinstrkey AND A.ITEM_SEQ = B.ITEM_SEQ
                AND A.ITEM_SEQ = C.ITEM_SEQ AND A.HIERARCHY_LEVEL_ORDER = B.SORT_ORDER
              ORDER BY A.HIERARCHY_LEVEL_ORDER DESC)
     WHERE ROWNUMBER < rownumbereend
       AND ROWNUMBER >= rownumberstart;
    

    Since the ORDER BY is applied after the ROWNUM is assigned in this case, your query is requested for a period of 5000 lines any arbitrariness. It would be perfectly valid for a single line to return in each of your 200 different calls or for a line to return in any of them.

    You definitely want to do something in the sense of the canonical askTom wire

    select *
      from ( select a.*, rownum rnum
               from ( YOUR_QUERY_GOES_HERE -- including the order by ) a
              where rownum <= MAX_ROWS )
     where rnum >= MIN_ROWS
    

    That said, it seems inconceivable that Tibco is unable to manage a cursor that returns more than a certain number of lines. You do a ton of work to return the data pages that are certainly not necessary. Unless you're saying that you somehow paralyzed your installation of Tibco giving him a ridiculously small amount of memory to process, something doesn't look good. A slider is just a pointer - it holds that no data - so the number of lines that you can extract a slider should have no impact on the amount of memory on the client application needs.

    As others have already pointed out, your exception handler is almost certainly do more harm than good. Return the error codes and error messages as from the OUT parameters, instead of simply allowing the exception to propagate deletes a ton of useful information (such as the mistake of the stack) and makes your process much less robust.

    Justin

  • using plsql table and ref cursor in oracle's 10 g

    Hi all
    Can someone give me an example of a scenario where we need to create a form manually based on a stored database procedure.
    And in this process, I created a pl/sql table and a Ref cursor at the database level.

    CREATE OR REPLACE PACKAGE SCOTT. TYPE BONUS_PKG IS bonus_rec
    IS (RECORD
    EmpNo bonus_EMP.empno%TYPE,
    Ename bonus_EMP.ename%TYPE,
    employment bonus_EMP.job%TYPE,
    SAL bonus_EMP.sal%TYPE,
    Comm bonus_EMP.comm%TYPE);

    TYPE b_cursor IS REF CURSOR RETURN bonus_rec;
    TYPE bontab IS TABLE OF bonus_rec INDEX DIRECTORY.

    PROCEDURE bonus_refcur (bonus_data IN OUT b_cursor);
    PROCEDURE bonus_query (bonus_data IN OUT bontab);
    END bonus_pkg;


    CREATE OR REPLACE PACKAGE BODY SCOTT. BONUS_PKG IS
    PROCEDURE bonus_query (bonus_data IN OUT bontab) IS
    II NUMBER;
    CURSOR bonselect IS
    SELECT empno, ename, job, sal, comm bonus_EMP ORDER BY empno;
    BEGIN
    OPEN bonselect.
    II: = 1;
    LOOP
    Look FOR bonselect IN
    .EmpNo bonus_data (ii),
    .ename bonus_data (ii),
    .job bonus_data (ii),
    .Sal bonus_data (ii),
    .comm bonus_data (ii);
    EXIT WHEN bonselect % NOTFOUND;
    II: = ii + 1;
    END LOOP;
    END bonus_query;

    PROCEDURE bonus_refcur (bonus_data IN OUT b_cursor) IS
    BEGIN
    Bonus_data OPEN to SELECT empno, ename, job, sal, comm bonus_EMP ORDER BY empno;
    END bonus_refcur;

    END bonus_pkg;

    I want to fill in the data in the forms manually is not using Forms data block Wizard and by program.

    Please answer...

    Can someone give me an example of a scenario where we need to create a form manually based on a stored database procedure.

    In general, you will use a block of proceedings based when you have a collection of data from several tables presented in a form and your username must be able to update the information displayed.

    In your sample code, looks like you are using Oracle Support document "Melting a block on a Stored Procedure - examples of Code [ID 66887.1]". If this is the case, continue to follow the document - it guides you through all the steps. There is no need to manually configure things that the data block Wizard will work for you!

    I want to fill in the data in the forms manually is not using Forms data block Wizard and by program.

    Why? Let the wizard block configuration data of your block based on a procedure for you. There is no need to manually browse the data! I did what you're trying, and it's more work needed. Leave forms to do the work for you. :)

    If you absolutely have to do things manually, I recommend that you use the PROCEDURE bonus_query (bonus_data IN OUT bontab) instead of bonus_refcur (bonus_data IN OUT b_cursor) . Then, in your code create a variable of type BONTAB, and then call the bonus_query procedure. Then, it's a simple case of a loop in the table of records returned by the bonus_query procedure. For example:

    DECLARE
       t_bonus    bonus_pkb.bontab;
    BEGIN
       bonus_pkg.bonus_query(t_bonus);
    
       FOR i in 1 .. t_bonus.count LOOP
          :YOUR_BLOCK.EMPLOYEE_NUMBER := t_bonus(i).empno;
          :YOUR_BLOCK.EMPLOYEE_NAME := t_bonus(i).ename;
          :YOUR_BLOCK.EMPLOYEE_JOB := t_bonus(i).job;
          :YOUR_BLOCK.EMPLOYEE_SALARY := t_bonus(i).sal;
          :YOUR_BLOCK.EMPLOYEE_COMMISSION := t_bonus(i).comm;
       END LOOP;
    END;
    

    This code example shows the basics, but as is the sample code - you will need to adapt to your situation.

    Also, I highly recommend that you look at the article inol listed. It is a very thorough debate on the REF CURSOR. If you have set up using a procedure based on the data source - it is more effective to spend the record table to your form that it must pass a ref cursor Using a ref cursor, you might as well just using a standard called cursor and loops on your named cursor. The effect is the same (a line returned at the same time creating lots of network traffic). Using the table of records is more efficient because the data set is returned if the network traffic is reduced.

    Hope this helps,
    Craig B-)

    If someone useful or appropriate, please mark accordingly.

  • return ref cursor

    I want to return ref cursor based on explicit cursors


    create or replace procedure get_extract (in_val in varchar2, return_cursor to sys_refcursor)
    is
    cursor c1 is select * from jumbo.
    cursor c2 is select * from mumbo.

    rec_j jumbo % rowtype;
    rec_m mumbo % rowtype;

    Start

    If in_val = am' then

    Open c1;

    loop
    Fetch c1 in rec_m;
    When exit c1% notfound;
    end loop;

    Open return_cursor SELECT * from rec_m;
    Close c1;

    elsif in_val = 'J' then

    Open c2;

    loop
    extract the c2 in rec_j;
    When the exit c2% notfound;

    end loop;
    Open return_cursor SELECT * from rec_j;
    Close c2;

    on the other

    Open return_cursor select double null.

    end if;

    end;
    /

    When I compile the procedure above, I get the error

    LINE/COL ERROR
    -------- ---------------------------------------------------
    20/24 PL/SQL: statement ignored
    20/38 PL/SQL: ORA-00942: table or view does not exist
    32/24 PL/SQL: statement ignored
    32/38 PL/SQL: ORA-00942: table or view does not exist

    so its occurring in the open return_cursor for... statement, what is the problem with above?

    user650888 wrote:
    I wrote the above and it worked but instead of having a select into the body of the procedure, I love it in an explicit cursor

    You can't do that. The sliders don't work that way. On the closest you could get would be something like:

    SQL> select * from t;
    
            ID DESCR
    ---------- ----------
             1 T One
             2 T Two
    
    SQL> select * from t1;
    
            ID DESCR
    ---------- ----------
             1 T1 One
             2 T1 Two
    
    SQL> create or replace procedure get_extract(in_val in varchar2,
      2                               return_cursor out sys_refcursor) is
      3     l_cur_m varchar2(100) := 'select * from t';
      4     l_cur_j varchar2(100) := 'select * from t1';
      5  begin
      6     if in_val = 'M' then
      7        open return_cursor for l_cur_m;
      8     elsif in_val = 'J' then
      9        open return_cursor for l_cur_j;
     10     else
     11        open return_cursor for select null from dual;
     12  end if;
     13  end;
     14  /
    
    Procedure created.
    
    SQL> var cur refcursor;
    SQL> exec get_extract('M', :cur);
    
    PL/SQL procedure successfully completed.
    
    SQL> print cur
    
            ID DESCR
    ---------- ----------
             1 T One
             2 T Two
    
    SQL> exec get_extract('J', :cur);
    
    PL/SQL procedure successfully completed.
    
    SQL> print cur
    
            ID DESCR
    ---------- ----------
             1 T1 One
             2 T1 Two
    

    John

  • How to perform procedures with REF CURSOR &amp; PLSQL settings table in SQL Dev?

    I have 3 SQL Developer. I create a procedure with a set of tables/PL/SQL as an input parameter and a SYS_REFCURSOR as output parameter.

    When I press the green arrow (Run button) block the dialog box run PL/SQL PL/SQL has no place at the PL/SQL table with records of entry and also to see the output of the SYS_REFCURSOR.

    I get the error ORA-06550 and many other errors when I run the present.

    How to do this please?

    In the debug code, lose the ABS. Prefix the SYS_REFCURSOR QC_SQL_DEVELOPER_TEST.
    Also, do not use same name of your settings on your bind variable (so e.g.: OUT_REF_CURSOR).
    REF CURSOR is supported output types, so you will get the output of their share in the output tab.
    However the output system does not recognize your own types as your PL/SQL table. You need to write an exit procedure yourself, indexing correctly, using the DBMS_OUTPUT.

    Have fun
    K.

Maybe you are looking for