Select in a procedure with cursor

Good Moring,

I met a problem that gives me in serious trouble... I have a Select clause:

SELECT count (*)

OF TD004_ENT_ORGAO_UO TD004

WHERE TD004. CODG_ENTIDADE = 1121742

AND TD004. NUMR_ANO_EXERCICIO = 2011

AND TD004. CODG_ORGAO = 02

AND TD004. CODG_UO = 001

My table is empty, and this query returns a count = 0, well, but, when I use this same query in a procedure that implements a cursor, I implement a way to control when and not to insert the records of this slider in my table:

OPEN cDIMENSAO.

LOOP

EXTRACT the cDIMENSAO IN EXERCISE, CODG_ORGAO, NOME_ORGAO, CODG_UO, NOME_UO, CODG_ENTIDADE, SK_ENTIDADE;

EXIT WHEN cDIMENSAO % NOTFOUND;

Start

v_count: = 0;

SELECT count (*) from V_COUNT

OF TD004_ENT_ORGAO_UO TD004

WHERE TD004. CODG_ENTIDADE = CODG_ENTIDADE

AND TD004. NUMR_ANO_EXERCICIO = EXERCISE

AND TD004. CODG_ORGAO = CODG_ORGAO

AND TD004. CODG_UO = CODG_UO;

IF V_COUNT = 0 THEN

INSERT APLIC. TD004_ENT_ORGAO_UO (SK_ENT_ORGAO_UO, NUMR_ANO_EXERCICIO, CODG_ORGAO, NOME_ORGAO, CODG_UO, NOME_UO, CODG_ENTIDADE, SK_ENTIDADE, DATA_CARGA)

VALUES (APLIC. SK004_ENT_ORGAO_UO. NEXTVAL, EXERCISE, CODG_ORGAO, NOME_ORGAO, CODG_UO, NOME_UO, CODG_ENTIDADE, SK_ENTIDADE, v_data_carga);

COMMIT;

END IF;

The problem occurs here, my control just v_count returns 1, even if the record is not inside of my table, is like where clasue is ignored. What can we do?

I use the Oracle XE 11g.

Thnks all.

Hello

the following SELECT in your block statement:

Count (td004.sk_ent_orgao_uo) SELECT INTO v_count

OF TD004_ENT_ORGAO_UO TD004

WHERE TD004. CODG_ENTIDADE = CODG_ENTIDADE

AND TD004. NUMR_ANO_EXERCICIO = EXERCISE

AND TD004. CODG_ORGAO = CODG_ORGAO

AND TD004. CODG_UO = CODG_UO;

causes an erroneous result. All right-hand-sides of the where clause is not the variables that you said earlier. In this case select is equal to

Count (td004.sk_ent_orgao_uo) SELECT INTO v_count

OF TD004_ENT_ORGAO_UO TD004

WHERE CODG_ENTIDADE = CODG_ENTIDADE

AND NUMR_ANO_EXERCICIO = EXERCISE

AND CODG_ORGAO = CODG_ORGAO

AND CODG_UO = CODG_UO;

quite a ' select tab where 1 = 1 '.

If you prefix the variablenames with "curattr_" then select

Count (*) SELECT INTO v_count

OF TD004_ENT_ORGAO_UO TD004

WHERE TD004. CODG_ENTIDADE = curattr_CODG_ENTIDADE

AND TD004. NUMR_ANO_EXERCICIO = curattr_EXERCICIO

AND TD004. CODG_ORGAO = curattr_CODG_ORGAO

AND TD004. CODG_UO = curattr_CODG_UO;

the where clause is is more "omitted".

Good bye

stratmo

Tags: Database

Similar Questions

  • stored procedure with cursor as param output

    This is the first time for me to test a stored procedure with a cursor as an out parameter. I performed the following:

    SQL > user_cur VARIABLE REFCURSOR; VARIABLE ret_code VARCHAR2; exec TEST_API. SEARCH_USER (: ret_code, ",", "John", ",: user_cur); print ret_code; print user_cur;

    I got the following error:

    Use: VAR [IABLE] [< variable > [NUMBER |]] TANK | CHAR (n [CHAR |]) BYTE]) |
    VARCHAR2 (n TANK). NCHAR. NCHAR (n) |
    NVARCHAR2 (n) | CLOB | NCLOB | REFCURSOR]]

    Can I know what is the problem?

    The purpose of the stored procedure is looking for user with the name 'john '.

    The declaration of input/output params to stored procedure is as follows:

    PROCEDURE SEARCH_USER
    (
    RETURN_CODE OUT VARCHAR2,
    USER_ID_IN IN VARCHAR2,
    POSITION_IN IN VARCHAR2,
    USERNAME_IN IN VARCHAR2,
    STATUS_IN IN VARCHAR2,
    USER_CUR_OUT ON REFCURSOR
    )

    Published by: user7383310 on October 19, 2008 21:05

    Published by: user7383310 on October 19, 2008 21:05

    refer here for the use of refcursors in pl/sql...
    http://download.Oracle.com/docs/CD/B14117_01/AppDev.101/B10807/06_ora.htm#sthref808

    You can code as...

    SQL> create or replace procedure p1(id number,csr out sys_refcursor) is  2  begin  3   open csr for select ename from emp where deptno = id;  4  end;  5  /
    
    Procedure created.SQL> var csr1 refcursorSQL> var n numberSQL> exec :n := 30;
    
    PL/SQL procedure successfully completed.
    
    SQL> exec p1(:n,:csr1);
    
    PL/SQL procedure successfully completed.
    
    SQL> print csr1
    
    ENAME----------ALLENWARDMARTINBLAKETURNERJAMES
    
    6 rows selected.
    
  • procedure with cursor does not properly

    Hai
    I m just a beginner I m trying to retrieve some records of my database and for this I m write the code as follows: -.


    create or replace procedure (p_month in NUMBER, p_year in NUMBER) export
    is
    Start
    declare
    v_ddoregcode VARCHAR2 (10);
    v_ddocode VARCHAR2 (6);
    v_prancode VARCHAR2 (12);
    v_Name VARCHAR2 (30);
    v_gc NUMBER (12,2).
    v_ec NUMBER (12,2).
    v_month NUMBER (2);
    v_year number 4;
    cursor c1 is select m.ddo_reg_code, m.ddo_code, m.pran_code, $m.name, i.gc, i.ec, i.month, i.year
    of nps_mst_new m, i_nps_trans I
    where m.pf_no = i.pf_no
    and i.month = p_month
    and i.year = p_year;
    Start
    Open c1;
    loop;
    Fetch c1 in v_ddoregcode, v_ddocode, v_prancode, v_name, v_gc, v_ec, v_month, v_year;
    dbms_output.put_line (v_ddoregcode | "| v_ddocode |" | v_prancode | "| v_Name |" | v_gc | "|)
    When exit c1% notfound;
    end loop;
    Close c1;
    end;
    end export;

    and it is compiled with errors please help me so that I can compile correctly and get the result I need.

    you could tell us what mistakes...

    loose the semicolon after the LOOP

    simplified version of the procedure (put it in a package)

    create or replace procedure export(p_month in NUMBER,p_year in NUMBER)
    is
    begin
       for rec in (select m.ddo_reg_code
                        , m.ddo_code
                        , m.pran_code
                        , m.name
                        , i.gc
                        , i.ec
                        , i.month
                        , i.year
                     from nps_mst_new m,i_nps_trans i
                    where m.pf_no=i.pf_no
                      and i.month=p_month
                      and i.year=p_year)
       loop
          dbms_output.put_line(rec.ddo_reg_code
                               ||rec.ddo_code
                               ||rec.pran_code
                               ||rec.name
                               ||rec.gc
                               ||rec.ec
                               ||rec.month
                               ||rec.year
                               );
       end loop;
    end export;
    
  • 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 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.

  • Windows 7 Pro black screen with cursor on all modes and no login screen

    OK so basically, it's how, my laptop decided to me-screw right when I need to make some adjustments to my final project for next week.

    Friday he started very well in class and at the end of the course at 6:30, I stopped him. I normally don't that often stopped because I usually find myself opening upward in an hour later. But I did this time and when I got home and turned on around 9:00, it started like this:

    Screen Compaq PhoenixBIOS > Windows boot animation > black screen with cursor mobile, no login screen

    No screen connection. No sound. Not nothing but a black screen and the cursor movement. So I force shutdown and turned it back, this time he asked a chkdsk and I ran it. A ton of stuff file unreadable came and it took all night to run through it all. Tried to start again and Windows Error Recovery came and I tried all Modes of security and start normally and all produce the same black screen and the cursor with no login screen.

    Then I used my Windows 7 dvd repair to try and system restore to a week before. That's where I noticed that windows had installed a critical update at 12:00 on Friday. Tried to restore before that, but he failed. Gave me an error 0 x 80070057 and said I should run chkdsk /r and then try again. Then I used the cmd prompt through dvd repair and he has seen all these things wrong file again once recovered things then realized hours later. Tried to restore the system again. Still the same error. A run chkdsk again through the cmd prompt, then he went to clean without errors or orphaned files or anything, but it took a lot of time. I used the Startup Repair, and he has not found anything wrong either. But still the same error the system restore.

    So I looked around online for the last two days, trying to figure out and that someone said to try CTRL + Alt + Delete, the sticky shift key thing. So I tried to boot the system again, same black screen with cursor movement. I did CTRL + Alt + Delete, nothing. Press and hold the SHIFT key, and a pop-up window asked FilterKeys. Press the SHIFT key 5 times, a popup asked about sticky keys. But that's all I can get it to do. Nothing else. I tried to boot into safe mode with F8, chose, each of them and that changes in screen resolution and the words "safe mode" in all the corners of the screen. If the repair dvd's while I start in safe mode, it will open as well in safe mode, but with the same black background mode. Tried running sfc/scannow through repair invites cmd of the dvd and it says a system repair is pending and he had to restart, and then run the sfc/scannow. Tried, but it doesn't do anything when I restart except go to Windows Error Recovery asking either start in any safe mode or normally. And then it's just black screen again.

    So I am at a complete loss what to do now. After all of this mess, it seems that this Windows Update Friday afternoon did something and when I booted it upward once again, his cause nothing but problems. I think it has something to do with the display and the graphics card drivers? It's as if the thing starts but I do not see anything either because the sticky keys appears, but sees nothing else, no matter what I do. Seriously, I don't want to this junk because this is a new hard drive and I was just able to retrieve my files from my old hard drive that had epic failures as well. And I just got this new specifications I wanted as well.

    Laptop Spec:

    Compaq CQ50-115nr
    OS: Windows 7 Professional
    HARD drive: Western Digital Scorpio Blue 320 GB SATA WD3200BEVT
    Processor: AMD Turion X 2 RM-70
    Graphics card: NVIDIA GeForce 8200 M G
    Memory: 3 GB RAM

    If someone could seriously help me I would be VERY happy.

    Hello

    This isn't good news.

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

    STOP: 0XC000021A

    Can be a difficult problem to solve, and you indeed need a technical help in a real store of the computer
    (not the leeks and the glances at a BestBuy or other BigBox stores) or system manufacturer support.

    Cause

    This error occurs when a subsystem of mode user, such as WinLogon or the Client Server Run-Time Subsystem (CSRSS), irremediably compromised and security can not be guaranteed. In response, the operating system goes into kernel mode. Microsoft Windows cannot run without WinLogon or CSRSS. Therefore, it is one of the rare cases where the failure of a user mode service can stop the system.

    Incompatible system files can also cause this error. This can happen if you restored your hard disk from a backup. Some backup programs may skip restoring system files which they determine are in use.

    Solve the problem

    Run the kernel debugger is not useful in this situation because the error occurred in a user mode process.

    Resolve an error in the user-mode device driver or system, third-party application service: Because the bug 0xC000021A control occurs in a user mode process, the most common culprits are third-party applications. If the error occurred after the installation of the new or updated device driver or service system, third-party applications, the new software should be removed or disabled. Contact the manufacturer of the software on a possible update.

    If the error occurs during the system startup, restart your computer, and then press F8 to character-based menu that displays the choice of operating system. In the Windows Advanced Options menu that results, select the last known good Configuration option. This option is most effective when a pilot or a service is added at a time. If the error is not resolved, try to manually remove the offending software. If the system partition is formatted with the (FAT) file allocation table, use a MS-DOS boot disk to access the hard disk of the computer. If the system partition is formatted with the NTFS file system, you may be able to use Safe Mode to rename or remove the defective software. If the defective software is used as part of the start-up procedure of the system Safe Mode, you must start the computer by using the Recovery Console to access the file. If a room newly installed if material is suspected, remove it to see if that fixes the problem.

    Try running the emergency recovery disk (ERD) and allow the system to repair any errors that it detects.

    Solve a problem of file system do not match: If you have recently restored your hard disk from a backup, check if there is an updated version of the backup/restore program available from the manufacturer. Make sure that the latest Windows Service Pack is installed.

    STOP: 0XC000021A<-- read="" this="">
    * 1314.html http://www.faultwire.com/solutions-fatal_error/Status-System-Process-terminated-0xC000021A-

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

    Look in the Event Viewer to see if something is reported on those.
    http://www.computerperformance.co.UK/Vista/vista_event_viewer.htm

    MyEventViewer - free - a simple alternative in the standard Windows Event Viewer.
    TIP - Options - Advanced filter allows you to see a period of time instead of the entire file.
    http://www.NirSoft.NET/utils/my_event_viewer.html

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

    It's my generic bluescreen convenience store - you can try Mode safe mode as suggested in article
    above - repeatedly press F8 that you start. Disks of Vista are probably necessary - if you do not try to repair it, you can borrow a friends because they are not protected against copying. You can also buy the physical disks
    good system machine cheap that you already own Windows (you have to reinstall them if)
    required). You can also repair disks on another computer.

    Here are a few ways to possibly fix the blue screen issue. If you could give the blue screen
    info that would help. Such as ITC and 4 others entered at the bottom left. And all others
    error information such as codes of STOP and info like IRQL_NOT_LESS_OR_EQUAL or PAGE_FAULT_IN_NONPAGED_AREA and similar messages.

    As examples:

    BCCode: 116
    BCP1: 87BC9510
    BCP2: 8C013D80
    BCP3: 00000000
    BCP4: 00000002

    or in this format:

    Stop: 0 x 00000000 (oxoooooooo oxoooooooo oxoooooooo oxooooooooo)
    Tcpip.sys - address blocking 0 x 0 00000000 000000000 DateStamp 0 x 000000000

    It is an excellent tool for displaying the blue screen error information

    BlueScreenView scans all your minidump files created during "blue screen of death," collisions
    Displays information on all the "crash" of a table - free
    http://www.NirSoft.NET/utils/blue_screen_view.html

    BlueScreens many are caused by old or damaged, in particular the video drivers drivers however
    There are other causes.

    You can do mode if necessary safe or the Vista DVD command prompt or
    Options recovery if your system is installed by the manufacturer.

    How to start on the System Recovery Options in Windows 7
    http://www.SevenForums.com/tutorials/668-system-recovery-options.html

    You can try a system restore to a point before the problem started when one exists.

    How to do a system restore in Windows 7
    http://www.SevenForums.com/tutorials/700-system-restore.html

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

    Start - type this in the search box-> find COMMAND at the top and RIGHT CLICK – RUN AS ADMIN

    Enter this at the command prompt - sfc/scannow

    How to fix the system files of Windows 7 with the System File Checker
    http://www.SevenForums.com/tutorials/1538-SFC-SCANNOW-Command-System-File-Checker.html

    How to analyze the log file entries that the Microsoft Windows Resource Checker (SFC.exe) program
    generates cbs.log Windows Vista (and Windows 7)
    http://support.Microsoft.com/kb/928228

    The log can give you the answer if there is a corrupted driver. (Says not all possible
    driver problems).

    Also run CheckDisk, so we cannot exclude as much as possible of the corruption.

    How to run the check disk at startup in Windows 7
    http://www.SevenForums.com/tutorials/433-disk-check.html

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

    Often drivers up-to-date will help, usually video, sound, network card (NIC), WiFi, part 3
    keyboard and mouse, as well as of other major device drivers.

    Look at the sites of the manufacturer for drivers - and the manufacturer of the device manually.
    http://pcsupport.about.com/od/driverssupport/HT/driverdlmfgr.htm

    Installation and update of drivers under Windows 7 (updated drivers manually using the methods above
    It is preferable to ensure that the latest drivers from the manufacturer of system and device manufacturers are located)
    http://www.SevenForums.com/tutorials/43216-installing-updating-drivers-7-a.html

    How to disable automatic driver Installation in Windows Vista - drivers
    http://www.AddictiveTips.com/Windows-Tips/how-to-disable-automatic-driver-installation-in-Windows-Vista/
    http://TechNet.Microsoft.com/en-us/library/cc730606 (WS.10) .aspx

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

    How to fix BlueScreen (STOP) errors that cause Windows Vista to shut down or restart
    quit unexpectedly
    http://support.Microsoft.com/kb/958233

    Troubleshooting Vista Blue Screen, error of JUDGMENT (and Windows 7)
    http://www.chicagotech.NET/Vista/vistabluescreen.htm

    Understanding and decoding BSOD (blue screen of death) Messages
    http://www.Taranfx.com/blog/?p=692

    Windows - troubleshooting blue screen errors
    http://KB.wisc.edu/page.php?id=7033

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

    In some cases, it may be necessary.

    Startup Options recovery or Windows 7 disk repair

    How to run a startup repair in Windows 7
    http://www.SevenForums.com/tutorials/681-startup-repair.html

    How to start on the System Recovery Options in Windows 7
    http://www.SevenForums.com/tutorials/668-system-recovery-options.html

    How to create a Windows 7 system repair disc
    http://www.SevenForums.com/tutorials/2083-system-repair-disc-create.html

    I hope this helps.

    Rob Brown - MS MVP - Windows Desktop Experience: Bike - Mark Twain said it right.

  • execution of the procedure with refcursor as output parameter

    Hi I have the package following a procedure with parameter as refcursor OUT.
    Here is an example of sample with the same structure with name in the other table, handling exceptions in my dev environment
    CREATE OR REPLACE PACKAGE TEST_PACK
      IS
    Type refCursor  is  REF CURSOR;
    PROCEDURE TEST_PROC (out_data out refCursor);
    END;
    
    
    CREATE OR REPLACE PACKAGE BODY TEST_PACK 
     IS
     Procedure test_proc (
            out_data out refCursor
                ) is
        --
        v_sql varchar2(4000);
       
        --
        begin
    
               v_sql := 'select
                        * from emp';
                       
            DBMS_OUTPUT.PUT_LINE ( 'Select Query is: '||v_sql );
    
            open out_data for v_sql;
    
            Exception
                when others then
                    DBMS_OUTPUT.PUT_LINE ( 'Error '|| SQLCODE ||','||SQLERRM );
    
       END;   
    end ;
    When I try to execute this procedure with the followig block
    DECLARE
       TYPE my_newcursor IS REF CURSOR;
       test_cur   my_newcursor;
      out_text      VARCHAR2 (4000);
    BEGIN
       TEST_PACK.test_proc(TEST_CUR) ;
       LOOP
          FETCH test_cur INTO out_text;    
          EXIT WHEN test_cur%NOTFOUND;
          dbms_output.put_line('Value of refcur is:'||out_text);
       END LOOP;
         CLOSE test_cur;  
    END;
    I get the following error
    ORA-00932: inconsistent datatypes: expected - got -
    ORA-06512: at line 8
    Could you please help me where I am doing wrong

    Thank you

    You must extract your data to an appropriate data type.

    (and note there is no need to declare your own ref cursor type as Oracle provides sys_refcursor at the end)

    for example

    SQL> set serverout on
    SQL>
    SQL> create or replace procedure test_proc(out_data out sys_refcursor) is
      2    v_sql varchar2(4000);
      3  begin
      4    v_sql := 'select * from emp';
      5    DBMS_OUTPUT.PUT_LINE ( 'Select Query is: '||v_sql );
      6    open out_data for v_sql;
      7  end;
      8  /
    
    Procedure created.
    
    SQL>
    SQL> declare
      2    rc     sys_refcursor;
      3    empRec emp%rowtype;
      4  begin
      5    test_proc(rc);
      6    loop
      7      fetch rc into empRec;
      8      exit when rc%notfound;
      9      dbms_output.put_line('Employee: '||empRec.empno||' - '||empRec.ename);
     10    end loop;
     11    close rc;
     12  end;
     13  /
    Select Query is: select * from emp
    Employee: 7369 - SMITH
    Employee: 7499 - ALLEN
    Employee: 7521 - WARD
    Employee: 7566 - JONES
    Employee: 7654 - MARTIN
    Employee: 7698 - BLAKE
    Employee: 7782 - CLARK
    Employee: 7788 - SCOTT
    Employee: 7839 - KING
    Employee: 7844 - TURNER
    Employee: 7876 - ADAMS
    Employee: 7900 - JAMES
    Employee: 7902 - FORD
    Employee: 7934 - MILLER
    
    PL/SQL procedure successfully completed.
    
    SQL>
    

    Why do you use a slider ref anyway?

    {: identifier of the thread = 886365}

  • iteration of table with cursor

    HELO. I have problem with cursor. I want to insert data in 2 tables but it have to depend on another temporary table. It's the trigger when-pressed key code:


    DECLARE
    CURSOR all_emps IS
    SELECT ORDERES_ID, BOOKS_BOOKSID
    Of orders_tmp
    ORDER BY orderes_id;

    Ord_ids TYPE TABLE IS ORDERS_TMP. TYPE % ORDERES_ID;
    Books_ids TYPE TABLE IS ORDERS_TMP. TYPE % BOOKS_BOOKSID;

    ord_ids ord_id;
    books_ids books_id;
    cli_id number (18.0);
    inx1 PLS_INTEGER;
    BEGIN
    Insert COMMANDS (ord_name, ord_lastname, ord_address, ord_phone, ord_date)
    values (: ORDERS.) ORD_NAME,: ORDERS. ORD_LASTNAME,: ORDERS. ORD_ADDRESS,: ORDERS. ORD_PHONE, sysdate);
    commit;

    OPEN all_emps.
    Get the all_emps COLLECT in BULK IN ord_id, books_id;
    CLOSE All_emps;

    FOR inx1 IN 1.ord_ids.count LOOP
    Select max (ord_id) in cli_id from orders;
    insert into ordered_books (order_cli_id, total_amount, books_id)
    values (cli_id,: SUB_CATEGORY.) AMOUNT, books_id);
    END LOOP;
    Go_Block ('BOOKS');
    hide_window ('ORDERS');
    hide_view ('ORDERS');

    END;

    And I get errors: BOOKS_ID and ORD_ID should be romance. Help, please

    Edited by: 863470 2011-09-10 05:20

    Your temporary table is defined with ON COMMIT DELETE ROWS? If so, omit validation and put it at the end of the procedure.

  • Procedure with THE parameters - creating a report

    I have the following procedure which is used in our applications (non-APEX) internal:
    PROCEDURE SelIssueActivityPublic (
                                                p_results           OUT     SYS_REFCURSOR,
                                                p_IssueID                    IN     ems.issue.issue_id%TYPE,
                                                p_TransactionID         OUT VARCHAR2
                 ) 
    The body of the procedure made a lot of treatment and inserts data into an intermediate table. The cursor ON the parameter then returns a SELECT statement in the staging table. Since it is possible that this procedure be struck several times (several users), transaction ID is used to match the data in the staging table to demand appropriate. The procedure then deletes the data from the staging table. (I'll post if necessary, but it is quite long, and since it is used successfully in other applications, I don't think it relates to my question).

    Asked me to create a report of the APEX data generated by the procedure. I've never used a procedure with an OUT parameter to create a report. I was hoping to assign transaction ID to a variable hidden on the loading of the page and then use it to poplulate the report. I'm not interested in the OUT parameter slider, I wrote my own SELECT statement to retrieve the data from the staging table.

    I tried to create a page that did that - agenda: H_P19_TRANSID, before the header calculation = EMS. EMS_READER. SelIssueActivityPublic (: H_P19_CURSOR, 454551,: H_P19_TRANSID) [454551 is a test question id], but I get the following error:
    ORA-06550: line 1, column 43: PLS-00222: no function with name 'SELISSUEACTIVITYPUBLIC' exists in this scope ORA-06550: line 1, column 7: PL/SQL: Statement ignored flowComp=H_P19_TRANSID
     Error ERR-1030 Error executing computation expression.
    He seems to think that SelIssueActivityPublic is a function, and I don't know why.

    Basically, I need to know how to use this procedure to put up my report. Once I can enter the transaction ID in a page element, I'll be set.

    How your procedure? You know that you can have the same procedure in the package with several definitions. Oracle allows you to use polymorphism, the ability to have multiple definitions of the same object with different signatures.

    Correction... You can not have a procedure of p in the case, are a function, since the calculation is expected to a way to fill the hidden element... You need a function to return the type of variable you want in the hidden element...

    Thank you

    Tony Miller
    Webster, TX

    Published by: Tony Miller on March 16, 2010 12:34

  • How to use the variable instead of the table name in the select statement of procedure

    I have a procedure with a select statement with dynamic from clause. How can I use instead of the name of the table variable.

    create or replace procedure scc_chemical_analysis
    is
    v_table_name varchar2 (100);
    Start

    declare
    cursor c1 is select * from v_table_name; -This is the variable name. How can I use it in the select statement.
    .
    .
    .
    .



    end;

    Hello

    something like that.

      1  declare
      2     vSQLString      VARCHAR2(32000);
      3  pTableName varchar2(1000):='EMP';
      4  BEGIN
      5     vSQLSTRING :=
      6  'SELECT ''x'' FROM ' || DBMS_ASSERT.sql_object_name(pTableName) || ' WHERE rownum<=1 ';
      7     EXECUTE IMMEDIATE vSQLSTRING;
      8* END;
    SQL> /
    
    PL/SQL procedure successfully completed.
    
  • How to optimize the select query executed in a cursor for loop?

    Hi friends,

    I run the code below and clocked at the same time for each line of code using DBMS_PROFILER.
    CREATE OR REPLACE PROCEDURE TEST
    AS
       p_file_id              NUMBER                                   := 151;
       v_shipper_ind          ah_item.shipper_ind%TYPE;
       v_sales_reserve_ind    ah_item.special_sales_reserve_ind%TYPE;
       v_location_indicator   ah_item.exe_location_ind%TYPE;
    
       CURSOR activity_c
       IS
          SELECT *
            FROM ah_activity_internal
           WHERE status_id = 30
             AND file_id = p_file_id;
    BEGIN
       DBMS_PROFILER.start_profiler ('TEST');
    
       FOR rec IN activity_c
       LOOP
          SELECT DISTINCT shipper_ind, special_sales_reserve_ind, exe_location_ind
                     INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
                     FROM ah_item --464000 rows in this table
                    WHERE item_id_edw IN (
                             SELECT item_id_edw
                               FROM ah_item_xref --700000 rows in this table
                              WHERE item_code_cust = rec.item_code_cust
                                AND facility_num IN (
                                       SELECT facility_code
                                         FROM ah_chain_div_facility --17 rows in this table
                                        WHERE chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
                                          AND div_id = (SELECT div_id
                                                          FROM ah_div --8 rows in this table 
                                                         WHERE division = rec.division)));
       END LOOP;
    
       DBMS_PROFILER.stop_profiler;
    EXCEPTION
       WHEN NO_DATA_FOUND
       THEN
          NULL;
       WHEN TOO_MANY_ROWS
       THEN
          NULL;
    END TEST;
    The SELECT inside the LOOP FOR cursor query took 773 seconds.
    I tried to use COLLECT in BULK instead of a cursor for loop, but it did not help.
    When I took the select query separately and executed with a value of the sample, and then he gave the results in a Flash of a second.

    All tables have primary key index.
    Any ideas what can be done to make this code more efficient?

    Thank you
    Raj.
    DECLARE
      v_chain_id ah_chain_div_facility.chain_id%TYPE := ah_internal_data_pkg.get_chain_id (p_file_id);
    
      CURSOR cur_loop IS
      SELECT * -- better off explicitly specifying columns
      FROM ah_activity_internal aai,
      (SELECT DISTINCT aix.item_code_cust, ad.division, ai.shipper_ind, ai.special_sales_reserve_ind, ai.exe_location_ind
         INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
         FROM ah_item ai, ah_item_xref aix, ah_chain_div_facility acdf, ah_div ad
        WHERE ai.item_id_edw = aix.item_id_edw
          AND aix.facility_num = acdf.facility_code
          AND acdf.chain_id = v_chain_id
          AND acdf.div_id = ad.div_id) d
      WHERE aai.status_id = 30
        AND aai.file_id = p_file_id
        AND d.item_code_cust = aai.item_code_cust
        AND d.division = aai.division;         
    
    BEGIN
      FOR rec IN cur_loop LOOP
        ... DO your stuff ...
      END LOOP;
    END;  
    

    Published by: Dave hemming on December 4, 2008 09:17

  • On Mac Book Pro, how can I select and delete spam with it opening?

    On Mac Book Pro, how can I select and delete spam with on their opening?

    Go to the junk mail folder in the Mail sidebar. Place the cursor in the message window and press command + A to select all of the messages in the window. Click on the trash in the toolbar or CTRL - RIGHT click and select the Recycle Bin on the shortcut menu.

  • Calling stored procedures with parameters with the database connectivity Toolkit

    Hi all

    I'm new to the forum and struggling to find a solution to a particular problem I have in this respect, using the LabVIEW Database Connectivity Toolkit on a project, I am currently working on my work.  I have a database in which I tables and stored procedures with parameters.  Some of these stored procedures have input, output and return parameters.

    I tried to follow this example, but to no avail: http://digital.ni.com/public.nsf/allkb/07FD130746083E0686257300006326C4?OpenDocument

    Such a stored procedure I am working on the implementation is named "dbo.getAllowablePNs", running "SELECT * from DeviceType" (DeviceType is the table).  In this case, it requires no input parameter, it has an output parameter that generates the table [cluster] and has a return parameter that returns an integer value (status code for execution) to show if an error occurred.  The DeviceType table has 3 columns; ID (PK, int not null), PN (nvarchar ((15), null) and NumMACAddresses (int, null).)  I have surpassed many examples and I talk to the support OR try to implement this and similar procedures stored in LabVIEW but have not been successful.  I am able to connect to the database with the VI of open connection without error, but spin in some confusion as a result of this step.  I then try to use the VI of parameter query create to call the stored procedure and set the parameters.  I guess I would then use the Set parameter value for each parameter that is connected to the entry of parameters on the previous query with parameters VI VI?  I am also having some confusion during and after these steps as well.  I would greatly appreciate advice or suggestions that anyone could have in this situation because I am not a SQL expert.  Also, I would be happy to provide more information that might be useful.

    Kind regards

    Jon

    Here's what I use to do this.  I think I had to change him create parameterized query VI for him to work.  There is a post on the forum about this somewhere.

  • I have a black screen with cursor before logon for Windows 7, 32-bit. Help, please.

    Tried to start in safe mode & start the laptop very well, but once I went back to the startup by default, face the same problem again.

    Hello

    Take a look at this thread and follow the same steps listed in the breast.

    http://answers.Microsoft.com/en-us/Windows/Forum/Windows_7-system/Windows-7-boots-to-black-screen-with-cursor-before/531df029-0dac-4392-9efe-1d35714cf136

    In particular, the bit on a SFC/scannow. Sometimes when you unplug a PC like that, you can damage some essential Windows files. A SFC scan should be able to fix it.

    This link contains a lot of other really good as well troubleshooting procedures.

    I hope this helps.

  • Procedure with the DML statements that insert values from 1 to 100 in only one table and it is matching word equivalent in the other

    Can someone help me create a procedure with the DML statements that insert values from 1 to 100 in a table "abc" and the procedure must connect the numbers into words in another table "xyz" without doing a commit explicitly. "."

    Currently on trial...

    SQL > create table abc (num number);

    Table created.

    SQL > create table xyz (num varchar2 (100));

    Table created.

    SQL > ed
    A written file afiedt.buf

    1. insert all
    2 values of 1 = 1 then in abc (num) (l)
    3 when the values of 1 = 1 then in xyz (num) (to_char (to_date(l,'j'), 'jsp'))
    4 * Select the level from dual connect by level<=>
    SQL > /.

    200 rows created.

    And the result...

    SQL > select * from abc;

    NUM
    ----------
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    ..
    ..
    ..
    98
    99
    100

    100 selected lines.

    SQL > select * from xyz;

    NUM
    ----------------------------------------------------------------------------------------------------
    one
    two
    three
    four
    five
    six
    seven
    eight
    nine
    ten
    Eleven
    twelve
    ..
    ..
    ..
    98
    Nineteen eighty
    Cent

    100 selected lines.

Maybe you are looking for