Same Cursor Output - Different Query

I am writing 2 cursors.
Cursor 1 which gives me A,B,C,D columns as output.
Cursor 2 gives me same A,B,C,D columns as output.
But the Logic to calculate inside the cursor Select Query is different.
I need to insert both A,B,C,D from Cursor 1 and Cursor 2 in same table by looping. Just curious to know do we have any way to insert the data by using same loop. Know it is impossible. Giving a try for any other solution.
Because I have 5 different cursors with same columns to be fetched and to insert in same table.
Planning to write a common insert script.

select a,b,c,d from ... query 1 where code in ('AB','CD')...
UNION ALL
select a,b,c,d from ... query 1 where code = 'EF'...
UNION ALL
select a,b,c,d from ... query 1 where code NOT IN ('GH')
But if only Code 'AB' is present, will that be fine to execute 'EF' query and 'GH' query also? All queries will have a minimum of 10 tables joins within 2 schema. If we write the condition before it will skip executing the 'EF' query and 'GH' query.
Which option is better?I do not see any problem with including the CODE conditions in the Select queries until the tables in the query contains the CODE column. If there is no table with CODE column, then you may have to include it somehow (Assuming different tables for each query).
Fine or not, it is for you to decide. If you use UNION/UNION ALL, all the queries shall be executed and the data, if present, shall be inserted into the target tables.
Moreover
select a,b,c,d from ... query 1 where code in ('AB','CD')...AND
select a,b,c,d from ... query 1 where code NOT IN ('GH')Do you not think it will return Duplicate records? Query where CODE NOT IN ('GH') would include CODES 'AB', 'CD', right? And using UNION ALL does not eliminate duplicates. So, if you have a Primary/Unique key, you are almost certain to encounter an error. Isn't it?
As an alternative, I think, you can use the Multitable Inserts as below:
INSERT ALL|FIRST         ----------> Use as suitable. ALL will process each condition irrespective of its TRUTH value; FIRST will stop evaluating the conditions after first match. If you do not specify, Default is ALL.
  INTO target_table (column_list)
VALUES (column_list_from_select_stmt)
select column_list, CODE
  from source_table(s);For more information on MultiTable inserts, Read Here.
Examples here.

Similar Messages

  • Query parameters with the same name and different values

    According to HTTP, multiple query or post parameters with the
    same name and different values are permitted. They are transfered
    over the wire in the following format -
    name1=val1&name1=val2&name1=val3
    The problem is that I can't see anyway of assigning multiple
    parameters with the same name and different values to the request
    object of mx.rpc.http.HTTPService. I have tried using the
    flash.utils.Dictionary object as it does strict key comparison but
    that doesn't work too. I have tried setting an array of values to a
    property of the request object but that sends the request to the
    server in the following format -
    name1=val1,val2,val3
    The java servlet engines throw exceptions when they see this.
    Any help would be greatly appreciated.

    If you're not on 8.1.4 move there. 8.1.3 had limitations in the wsrp
    release.
    wrote:
    I have an html select box that contains several values, and multiple
    selection is enabled. When my code runs as a remote portlet, the
    following is showing up in the soap monitor when I select multiple
    values and submit the form:
    <urn:interactionParams>
    <urn:portletStateChange>cloneBeforeWrite</urn:portletStateChange>
    <urn:interactionState>_action=addEmployeesToGroup</urn:interactionState>
    <urn:formParameters
    name="P62005wlw-select_key:{actionForm.selectedEmployees}OldValue">
    <urn:value>true</urn:value>
    </urn:formParameters>
    <urn:formParameters
    name="P62005wlw-select_key:{actionForm.selectedEmployees}">
    <urn:value>beatest1</urn:value>
    </urn:formParameters>
    In this case, I selected beatest1 and beatest2, but only beatest1 comes
    through to the remote portlet. Is this a known bug, and, if so, is
    there a patch or workaround available?
    Thanks in advance,
    Andy

  • Generating same SApScript output to different output methods

    Hi All,
    Can someone tell me whether it's possible to generate different out methods using the same SAPScript output. if so how to do it ??
    i.e : e-mail & printer or fax & printer.
    thanks in advance
    Dhanushka.

    Hi,
    Is there a BAPI to send the spool request as an e-mail or fax.
    About the sequence of events:
    Generating of the spool request is done using the open_form right. Once the form is closed get the spool id and send it by e-mail or fax ???.
    is this correct
    thanks & regards
    Dhanushka.

  • Different query for same view showing on different page as list view web part

    Hi all,
    If you have three pages and want to add Documents library as list view web part to these three pages with different query (Programmatically), Do you need to create three different views for Documents library or it is possible to have different query when
    I add the list view web part to the page?
    thanks and appreciate all kind of advice.

    When you add a List View Web Part to a page, SharePoint actually copies the selected view query into the Web Part itself. For example:
    You create a custom view on a list called "Mede71's View" and you configure it only show the Title column
    You add a List View Web Part to a page and update the settings to use the "Mede71's View"
    You go back to your list and change "Mede71's View" and add the "Modified Date" column
    Your List View Web Part will not reflect this change because in step 2 the Query from the view was copied into the List View Web Part
    When you programmatically add the List View Web Part, you can either assign it to an existing view or supply the query directly. If you want to instruct users to be able to add their own web parts pointing to those views in the future, I would recommend
    creating the views first.
    Dimitri Ayrapetov (MCSE: SharePoint)

  • Output different data based on user select

    Hi everyone,
    Quick question, I would like to output different report columns based on user select, eg., users would be presented with two choices in a radiobutton list, eg., 1 and 2.
    I have query results that contain columns A, B, C, D, E, F, G.
    If user selects 1 then the output should be columns A, B, C, D, E.
    If user selects 2 then the output should be columns A, B, C, F, G.
    I am sure this is possible and easy? If so, what topic should I be reading/searching internet on?
    Please advise.
    Thanks!

    I would say that this is most often something that your user interface should be dealing with (i.e. which columns should be shown).
    There is no way to do that in SQL.
    In PL/SQL it is a simple situation of creating two cursors and simply deciding which one to open.
    <pre>declare
    l_cur sys_refcursor;
    begin
    if :user_selection = 1 then
    open l_cur for select A, B, C, D, E from tbl;
    else
    open l_cur for select A, B, C, F, G from tbl;
    end if;
    -- use the cursor
    close l_cur; -- or return to user interface
    end;
    /</pre>
    Hope this helps.

  • LinkedHashMap problem (Same key but different value)

    Dear Friends,
    There is problem in LinkedHashMap for same key but different values.
    I want both values of same key as Output.
    Plz help me from an example code & it's output
    LinkedHashMap<Object, LinkedList<Object>> linkhash = new LinkedHashMap<Object, LinkedList<Object>>();
    LinkedList<Object> ll6 = new LinkedList<Object>();
              LinkedList<Object> ll7 = new LinkedList<Object>();
              LinkedList<Object> ll9 = new LinkedList<Object>();
    objectName="Listitem";
              ll6.add("id\tlisti");
              ll6.add("tag\tlistcell");
              ll6.add("tag\tlistcell");
              linkhash.put(objectName, ll6);
              System.out.println("List is "+linkhash);
              objectName="Listcell";
              ll7.add("id\tlistc");
              ll7.add("label\tCEO");
              linkhash.put(objectName, ll7);
              System.out.println("List is "+linkhash);
              objectName="Listcell";
              ll9.add("id\tlistc1");
              ll9.add("label\tNKC");
              linkhash.put(objectName, ll9);
              System.out.println("List is "+linkhash);
    output is
    List is {Listitem=[id     listi, tag     listcell, tag     listcell]}
    List is {Listitem=[id     listi, tag     listcell, tag     listcell], Listcell=[id     listc, label     CEO]}
    List is {Listitem=[id     listi, tag     listcell, tag     listcell], Listcell=[id     listc1, label     NKC]}
    I want output as
    List is {Listitem=[id  listi, tag  listcell, tag  listcell],Listcell=[id   listc, label CEO], Listcell=[id     listc1, label  NKC]}
    Plz help me
    Thanks Friend
    Edited by: kkcnkc on Apr 1, 2009 6:47 AM

    Double post. Locking.

  • Merge of two same items with different Qty in po

    Hi Experts,
    Is it possible to merge two Same items with different Quantity into 1.
    For Eg:- 2 similar  items  with qty 2 & 3 must show 5 qty appearing once.Is it possible through Transnotification what should be the query.
    Mona

    Hi Mona,
    If you want to display a Purchase Order on screen summarized by item, set the "Summary Type"  to "By Item" (by default it is "No Summary"). The PO lines will then be summarized by item with total quantity for each item.
    If you want to display it on the printout then you need to modify the PLD. It is quite easy actually. You can use the Repetitive Area Footer to display the summary of each item and set all fields in the Repetitive Area to be not visible and set the height to minimum height.
    Cheers,
    Marini

  • How to call a Stored Procedure with a REF CURSOR output parameter

    I am looking forward an example that call a stored function/procedure with a REF CURSOR output parameter and get the result.
    In other words, I have a stored function/procedure that execute a SELECT statement using the OCI library and then it could get the values of each column and each row.
    I put a code snippet, it have only the main thing to call a simple stored procedure and print the name of each column of the cursor, but I couldn´t to print out the values in the table that call the stored procedure.
    I understand that the next step, it is to call a OCIStmtFetch.
    How to associate the cursor with the OCIStmtFetch?
    If you need more information, only tell me.
    I am using ANSI C with HP-UX Operative System (C for HP-UX) and Oracle 10g.
    Regards.
    Antonio Garcia
    /* callOracleSP */
    #include <stdio.h>
    #include <string.h>
    #include <oci.h>
    #include <stdlib.h>
    char* pConnectChar ="server";
    char* pUsernameChar = "user";
    char* pPasswordChar = "passwd";
    char* sqlCharArray1 = "BEGIN SP_GETCITIES(:s, :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("OCILogon retval=%d\n",retval);
    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 = OCIBindByPos(pOciStatement,&pOciBind[0], pOciError, (ub4) 1, (void *)&state_key,
         (sb4) sizeof(state_key), SQLT_STR, (void *) 0, (ub2 *) 0, (ub2 *)0,(ub4)0, (ub4 *)0, (ub4) OCI_DEFAULT);
    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, (ub4) OCI_DEFAULT);
    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, (ub4) OCI_DEFAULT);
    printf("StmtExecute retval=%d\n",retval);
    /* How to get the values of the cursor? */
    /* Get number of parameters of the Cursor */
    OCIAttrGet((void *) pOciStatCursor, (ub4)OCI_HTYPE_STMT, (void*) &parmcnt,(ub4 *) 0,
         (ub4)OCI_ATTR_PARAM_COUNT, pOciError);
    printf("\nNumber of parameters of the cursor = %d\n",parmcnt);
    for (int pos = 1; pos <= (int)parmcnt; pos++)
         OCIAttrGet((void *) pOciStatCursor, (ub4)OCI_HTYPE_STMT, (void*) &pos2,(ub4 *) 0,
              (ub4)OCI_ATTR_CURRENT_POSITION, pOciError);
         retval = OCIParamGet((void *)pOciStatCursor, (ub4)OCI_HTYPE_STMT, pOciError, (void **)&pOciParam,
              (ub4) pos );
         OCIAttrGet((void*) pOciParam, (ub4) 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("Column %i\tNAME = %.*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('NY', 10, 'NEW YORK')
    INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES('NY', 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 are T/SQL specific global variables. */
    TYPE RCT1 IS REF CURSOR;/*new weak cursor definition*/
    END globalPkg;
    CREATE OR REPLACE PROCEDURE SP_ADDCITY(
    P_STATE_CODE IN VARCHAR,
    P_CITY_CODE      IN NUMBER,
    P_CITY_NAME      IN VARCHAR2,
    P_RETURN IN OUT NUMBER)
    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 := SQL%ROWCOUNT;
    EXCEPTION
    WHEN TOO_MANY_ROWS THEN
    StoO_rowcnt := 2;
    WHEN 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 RC1 FOR
    SELECT STATE_CODE, CITY_CODE, CITY_NAME
    FROM CITIES
    WHERE STATE_CODE = STATE_KEY
    ORDER BY CITY_CODE;
    StoO_rowcnt := SQL%ROWCOUNT;
    EXCEPTION
    WHEN OTHERS THEN
    StoO_rowcnt := 0;
    StoO_error := SQLCODE;
    StoO_errmsg := SQLERRM;
         END;
    /

    Hi Mark,
    Thanks for your recommendations.
    I change the code with OCIDefineByPos, one for each parameter from cursor and then use the OCIStmtFetch.
    I don´t receive a error when call OCIDefineByPos, but when I call OCIStmtFetch receive a -1 error number.
    What is wrong with the code?
    The script is the same.
    I need your help!
    Best Regards!
    Antonio Garcia (Mexico)
    This the new code:
    #include <stdio.h>
    #include <string.h>
    #include <oci.h>
    #include <stdlib.h>
      char*   pConnectChar ="ORAC617";
      char*   pUsernameChar = "C617_005_DBO_01";
      char*   pPasswordChar = "Tempora1";
      char*   sqlCharArray1 = "BEGIN SP_GETCITIES(:s, :c); END;";
      int     retval;
      ub4 parmcnt=0;
      ub4 pos2=0;
      sb2   *c_indp;
      text *pcoln[20], *name,*name2;
      ub4 namelen[20],len;
      ub2 type,size;
      char state_key[5];
      OCIDefine        *pdef;
      OCIBind          *p_bnd;
      ub1          **c_buf;
      OCIStmt*     pOciStatement;      /* Statement handle */
      OCIStmt*     pOciStatCursor;     /* Statement handle */   
      OCIError*    pOciError;          /* Error handle */
      OCIEnv*      pOciEnviron;        /* Environment handle */
      OCIServer*   pOciServer;         /* Server handle */  
      OCISession*  pOciSession;        /* Session handle */
      OCISvcCtx*   pOciServiceContext; /* Service Context handle */
      OCIBind*     pOciBind[500];      /* Bind handle */
      OCIParam*    pOciParam;          /* Param handle */
      int OCI_Fetch(OCIStmt *p_select,OCIError *p_err, int *piOcc)
      int iOcc, rc; 
      rc=OCIStmtFetch(p_select,p_err,1,OCI_FETCH_NEXT,OCI_DEFAULT);
      printf("rc fetch %i",rc);
      if(rc==0&&piOcc!=NULL){
           printf("entro al if");
        iOcc=*piOcc;
        *piOcc=iOcc+1;
      return rc;
    int main()
    int pos,i=0,rc;
      retval = OCIEnvCreate(&pOciEnviron, OCI_DEFAULT, NULL, NULL, NULL, NULL,0,NULL);
      printf("EnvCreate retval=%d\n", retval);
      retval = OCIEnvInit(&pOciEnviron, OCI_DEFAULT, 0, NULL);
      printf("EnvInit retval=%d\n",retval);
      retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciError, OCI_HTYPE_ERROR, 0, NULL);
      printf("HandleAlloc OCI_HTYPE_ERROR retval=%d\n",retval);
      retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciServiceContext, OCI_HTYPE_SVCCTX, 0, NULL);
      printf("HandleAlloc OCI_HTYPE_SVCCTX retval=%d\n",retval);
      retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciStatement, OCI_HTYPE_STMT, 0, NULL);
      printf("HandleAlloc OCI_HTYPE_STMT retval=%d\n",retval);
      retval = OCILogon(pOciEnviron,pOciError,&pOciServiceContext,(unsigned char *)pUsernameChar,
                  strlen(pUsernameChar), (unsigned char *)pPasswordChar, strlen(pPasswordChar),
                    (unsigned char *)pConnectChar,strlen(pConnectChar));
      printf("OCILogon retval=%d\n",retval);
      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);
      printf("HandleAlloc OCI_HTYPE_STMT retval=%d\n",retval);
      retval = OCIBindByPos(pOciStatement,&pOciBind[0], pOciError, (ub4) 1, (void *)&state_key,
                 (sb4) sizeof(state_key), SQLT_STR, (void *) 0, (ub2 *) 0, (ub2 *)0,(ub4)0, (ub4 *)0, (ub4) OCI_DEFAULT);
      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, (ub4) OCI_DEFAULT);
      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, (ub4) OCI_DEFAULT);
      printf("StmtExecute retval=%d\n",retval);
      c_buf=(ub1 **)calloc(sizeof(ub1 *),3);
      c_indp=(sb2 *)calloc(sizeof(sb2 *),3);
      // Get number of parameters of the Cursor
      OCIAttrGet((void *) pOciStatCursor, (ub4)OCI_HTYPE_STMT, (void*) &parmcnt,(ub4 *) 0,
                  (ub4)OCI_ATTR_PARAM_COUNT, pOciError);
      printf("\nNumber of parameters of the cursor = %d\n",parmcnt);
      for (pos = 1; pos <= (int)parmcnt; pos++)
           OCIAttrGet((void *) pOciStatCursor, (ub4)OCI_HTYPE_STMT, (void*) &pos2,(ub4 *) 0,
                (ub4)OCI_ATTR_CURRENT_POSITION, pOciError);
           retval = OCIParamGet((void *)pOciStatCursor, (ub4)OCI_HTYPE_STMT, pOciError, (void **)&pOciParam,(ub4) pos );
           // Get the column name
           OCIAttrGet((void*) pOciParam, (ub4) OCI_DTYPE_PARAM,(void*) &name,(ub4 *) &len, (ub4) OCI_ATTR_NAME,(OCIError *)pOciError );
            // Get the column datatype
           OCIAttrGet((void*) pOciParam, (ub4) OCI_DTYPE_PARAM,(void*) &type,(ub4 *)0,(ub4)OCI_ATTR_DATA_TYPE,(OCIError *)pOciError);      
            // Get the column size
           OCIAttrGet((void*) pOciParam, (ub4) OCI_DTYPE_PARAM,(void*) &size,(ub4 *)0,(ub4)OCI_ATTR_DATA_SIZE,(OCIError *)pOciError);
           printf("Column %i\tNAME = %.*s \ttype %d \tsize %d\n",pos,len,name,type,size);
           // OCIDefine ByPos, one for each parameter
           // c_buf store the STATE_CODE, CITY_CODE and CITY_NAME columns from the cursor
           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);     
          printf("OCIDefineByPos retval=%d\n,rc);
      // call OCIStmtFetch. In the next line, I receive the error
      rc=OCIStmtFetch(pOciStatCursor,pOciError,1,OCI_FETCH_NEXT,OCI_DEFAULT);
      printf("rc fetch %i",rc);
      return 0;
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Same Sequence# with different applied value in v$archived_log

    Hi everyone,
    I have an issue with one of the dataguard servers here.
    Basically, looking at the v$managed_standby, it is still applying the latest archived log sequence.
    However when I checked for unapplied archived log from v$archived_log, I found at least 1 sequence# which was quite old (around a few days old) not applied.
    my query to check this is:
    SELECT sequence# from v$archived_log where applied = 'NO';result:
    SEQUENCE#
        40154
        40546with a different query I found an interesting result
    select sequence#, recid, stamp, status, applied from v$archived_log where sequence# in (40154, 40546);result:
    SEQUENCE#      RECID      STAMP S APP
        40154       8093  777156019 D NO
        40154       8095  777156053 D YES
        40546       8486  777673729 D NO
        40546       8487  777673734 D YESAt the time I ran this query, the v$managed_standby are as follow:
    select process, status, sequence# from v$managed_standby;result:
    PROCESS   STATUS        SEQUENCE#
    ARCH      CLOSING           40562
    ARCH      CLOSING           40557
    MRP0      APPLYING_LOG      40563
    RFS       IDLE                  0
    RFS       IDLE              40563A simple solution to get those un-applied archived log to be applied is to restart the standby database instance.
    Another finding from the production database:
    select recid, stamp, sequence#, creator, registrar, standby_dest from v$archived_log where sequence# in (40154, 40546);result:
    RECID      STAMP  SEQUENCE# CREATOR REGISTR STA
    45446  777156011      40154 ARCH    ARCH    NO
    45447  777156017      40154 LGWR    LGWR    YES
    45450  777156051      40154 ARCH    ARCH    YES
    46231  777673709      40546 ARCH    ARCH    NO
    46232  777673728      40546 LGWR    LGWR    YES
    46233  777673733      40546 ARCH    ARCH    YESThe question is of course, why is this happening?
    Can this be prevented?
    Thank you,
    Adhika

    CKPT wrote:
    I have an issue with one of the dataguard servers here.
    Basically, looking at the v$managed_standby, it is still applying the latest archived log sequence.
    However when I checked for unapplied archived log from v$archived_log, I found at least 1 sequence# which was quite old (around a few days old) not applied.
    my query to check this is:
    SELECT sequence# from v$archived_log where applied = 'NO';result:
    SEQUENCE#
    40154
    40546
    Even if old archives applied or not, it will keep transfer the archivelogs from primary. Please confirm that you been executed above query in standby.. is it?Yes I ran it from the standby database
    CKPT wrote:
    with a different query I found an interesting result
    select sequence#, recid, stamp, status, applied from v$archived_log where sequence# in (40154, 40546);result:
    SEQUENCE#      RECID      STAMP S APP
    40154       8093  777156019 D NO
    40154       8095  777156053 D YES
    40546       8486  777673729 D NO
    40546       8487  777673734 D YES
    How many remote/standby destinations you have in your DR setup?
    Might this query you have executed in primary, You should always use DEST_ID when executing from primary (or) do check in standby database, Because the applied column you have to check in standby , If you see above the same sequence showing applied in one destination & not applied on other instance, so please do select for dest_2 or in standby.I have only 1 standby destination.
    The query above was executed in the standby database server as well as to show that the same sequence# has different result in the applied column.
    CKPT wrote:
    The question is of course, why is this happening?
    Can this be prevented?What is your Online redo log file size (or) how much average archive log file size?
    This issue happens when Network glitch while transferring archives from primary to standby RFS , So when is big enough in such conditions it will be in status can be WAIT_FOR_LOG.
    BTW, which redo transport you are using? -- recommended to use LGWR
    Is there any network problem?
    check for exact problem either from primary alert log file or from below query,
    SQL> select severity,error_code,message,to_char(timestamp,'DD-MON-YYYY HH24:MI:SS') from v$dataguard_status;
    SQL> select sequence#, to_char(completion_time,'DD-MON-YYYY HH24:MI:SS') from v$archived_log where sequence# in (40154, 40546);
    HTH.The redolog file size is 100MB and so does the archive log file size.
    I'm using LGWR ASYNC
    these are the result of the query which I modified slightly:
    query:
    select severity,error_code,message,to_char(timestamp,'DD-MON-YYYY HH24:MI:SS') from v$dataguard_status where message like '%40154%' or message like '%40546%';result:
    SEVERITY ERROR_CODE MESSAGE                                                                                              TIMESTAMP
    Warning           0 LNS: Standby redo logfile selected for thread 1 sequence 40546 for destination LOG_ARCHIVE_DEST_2    11-MAR-2012 20:28:44
    Warning           0 ARC1: Standby redo logfile selected for thread 1 sequence 40546 for destination LOG_ARCHIVE_DEST_2   11-MAR-2012 20:28:49The message for the 40154 must have been purged.
    It appeared to me that sequence 40546 has been sent twice, by LNS and ARC1.
    query:
    select sequence#, registrar, creator, standby_dest, dest_id, to_char(completion_time,'DD-MON-YYYY HH24:MI:SS') completion_time from v$archived_log where sequence# in (40154, 40546);result:
    SEQUENCE# REGISTR CREATOR STA    DEST_ID COMPLETION_TIME
        40154 ARCH    ARCH    NO           1 05-MAR-2012 20:40:11
        40154 LGWR    LGWR    YES          2 05-MAR-2012 20:40:17
        40154 ARCH    ARCH    YES          2 05-MAR-2012 20:40:51
        40546 ARCH    ARCH    NO           1 11-MAR-2012 20:28:29
        40546 LGWR    LGWR    YES          2 11-MAR-2012 20:28:48
        40546 ARCH    ARCH    YES          2 11-MAR-2012 20:28:53This query proved that the primary database is actually trying to send twice with a different completion time.
    Why does the primary database has to send twice?
    Thanks for replying,
    Adhika

  • Cursor in select query

    how i use cursor in select query ?
    I have 2 table
    1. emp
    2. dept
    i want output like
    Manager
    a
    b
    c
    Clark
    d
    e
    f
    HOD
    g
    h
    i
    by using cursor

    We wouldn't help you to learn something if we just give you an answer.
    Show some effort by yourself first, then ask what specific problem you encountered and you'll find this forum much more willingness to help.

  • OPEN cursor for large query

    OPEN cursor
    When you OPEN a cursor for a mult-row query, is there a straightforward way that you can have it only retrieve a limited number of rows at a time and then automatically delete those rows as you do the FETCH against them? I'm thinking of setting up multiple sequential cursors, and opening and closing them as the rows are processed. But I'm hoping there might be a better way.
    The problem is that I'm running out of TEMPORARY during the OPEN cursor stage.
    The application I am working on needs to work in Standard Edition and Personal Edition versions of Oracle.
    Thank you.

    Thanks - I had read the documentation before, but interpreted it differently.
    What I had read was in:
    http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#i45288
    The extract of interest was:
    Opening a Cursor
    Opening the cursor executes the query and identifies the result set, which consists of all rows that meet the query search criteria. For cursors declared using the FOR UPDATE clause, the OPEN statement also locks those rows. An example of the OPEN statement follows:
    DECLARE
    CURSOR c1 IS SELECT employee_id, last_name, job_id, salary FROM employees
    WHERE salary > 2000;
    BEGIN
    OPEN C1;
    Rows in the result set are retrieved by the FETCH statement, not when the OPEN statement is executed.
    My interpretation was that the result of the query was put into the temporary tablespace and then retrieved into the program during the FETCH.
    Assuming I was wrong, what I'm wondering now is how I can possibly be running out of temporary space during this OPEN cursor process.

  • SAP XI 3.0 Same source for different target in std Value mapping function

    Hi,
    We have replicated 4 value mapping entries from R3 to XI having the same Context , Agency , Schema and value for source, but each of the 4 values has the same Context and Agency but different Schema and Value respectively.
    To illusstate :
    Source                             |Target
    Context Agency Schema    Value -----Context Agency   Schema     Value
    CS1      AS1      SS1      1        CT1       AT1      ST1       A
    CS1      AS1      SS1      1        CT1       AT1      ST2       A
    CS1      AS1      SS1      1        CT1       AT1      ST3       B
    This value mapping is not working and we always get the source value as the result.
    We are wondering if the reason for this is that we use the same source for different targets. But we are not 100 % sure of it.
    When I read the documentation on Value mapping or when we use the value mapping standard function in graphical mapping, we pass the context , agency and schema of the source and target respectively and the source value to get the target value, and this combination is always unique in our case as seen in the above example.
    Has anyone faced this kind of an issue, if yes I would appreciate if anyone could help us resolve this problem.
    Thanks in advance.
    regards,
    Advait

    Hi Advait,
    From the below what I understand is that you are not able to do value mapping for the follwoing
    1     A
    2     A
    3     B
    As value mapping allow one to one mapping only. Please do it like as mentioned below
    1     1*A
    2     2*A
    3     3*B
    Then in the graphical mapping of Integration Repository do the mapping for the same as shown below
    source field > VALUEMAPPING> UDF--> TARGET Field
    In UDF suppress the value of  1* , 2* , 3* which can be done as follows
    create one UDF with one input field
    //write the code as below to suppress the field
    return input.substring(2);
    Here the davantage of using 1* , 2* , 3* etc is that you have the option to use value mapping for 100 values which I think is not normally the case for any Interface.
    If you have same source you can do the same thing for that.
    Hope this helps you to resolve your query.
    Thanks & Regards
    Prabhat

  • Loop 2 times on same cursor

    Hi,
    If you open a cursor and loop on it, and after the loop is finished, then loop on it again (without closing the cursor in between), will it loop again on the same data as was queried during the opening of the cursor? In other words, will the read-consistency of the active set created when opening the cursor be maintained when looping the second time?
    I need to check the data of table A, against table B (= first loop), and then empty table B and fill it with the data from table A (= second loop). But I need to be sure that the data from table A used to compare in the first loop, is exactly the data that is written to table B.
    Thanks,
    Roel

    Hi, Roel,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    If you're asking about a DML statement, such as UPDATE, the CREATE TABLE and INSERT statements should re-create the tables as they are before the DML, and the results will be the contents of the changed table(s) when everything is finished.
    Always say which version of Oracle you're using.
    It's unclear why you need two cursors. You can probably do everything you want to in a single MERGE statement, especially if you're using Oracle 11, where MERGE can DELETE rows.

  • Different query plan on different schema

    Hi gurus
    i have a problem witha a select: i explain the same select on differnt schema and i obtain a different query plan.The tables have the same key,index and data.
    which are the possible reason for this behavior ?

    This is the first select
    - <select-statement>
    - <sort type="order-by">
    - <nested-loops type="outer">
    - <nested-loops type="outer">
    - <hash-join>
    - <inlist-iterator>
    - <table-access object="tbl_0009" type="by-index-rowid">
    <index object="ky0009_1" type="range-scan" />
    </table-access>
    </inlist-iterator>
    - <table-access object="tbl_0210" type="by-index-rowid">
    - <nested-loops>
    - <table-access object="tbl_0010" type="by-index-rowid">
    <index object="ky_0010_2" type="range-scan" />
    </table-access>
    <index object="ky0210_1" type="range-scan" />
    </nested-loops>
    </table-access>
    </hash-join>
    - <table-access object="tbl_0008" type="by-index-rowid">
    <index object="ky0008_1" type="unique-scan" />
    </table-access>
    </nested-loops>
    - <table-access object="tbl_0008" type="by-index-rowid">
    <index object="ky0008_1" type="unique-scan" />
    </table-access>
    </nested-loops>
    </sort>
    </select-statement>
    The second
    - <select-statement>
    - <sort type="order-by">
    - <nested-loops type="outer">
    - <nested-loops type="outer">
    - <nested-loops>
    - <nested-loops>
    - <table-access object="tbl_0010" type="by-index-rowid">
    <index object="ky_0010_2" type="range-scan" />
    </table-access>
    - <table-access object="tbl_0210" type="by-index-rowid">
    <index object="ky0210_2" type="range-scan" />
    </table-access>
    </nested-loops>
    - <inlist-iterator>
    - <table-access object="tbl_0009" type="by-index-rowid">
    <index object="ky0009_1" type="range-scan" />
    </table-access>
    </inlist-iterator>
    </nested-loops>
    - <table-access object="tbl_0008" type="by-index-rowid">
    <index object="ky0008_1" type="unique-scan" />
    </table-access>
    </nested-loops>
    - <table-access object="tbl_0008" type="by-index-rowid">
    <index object="ky0008_1" type="unique-scan" />
    </table-access>
    </nested-loops>
    </sort>
    </select-statement>
    The select is the same
    SELECT datareg,decode(dare,null,0.00,dare) dare,decode(avere,null,0.00,avere)avere,protocollo,contocontr,numdo,datad,cocp,ccde9,conto codiceconto,contocliprincipale contocli, 0.00 dareSaldo, 0.00 avereSaldo , null conto_saldo FROM (SELECT /*+ ordered use_nl ( tbl_0210)*/ tbl_0210.coso210 conto, id10, datar10 datareg, proto10 protocollo, ' ' || pianoconti.prefi8 || '.' || LPAD(pianoconti.mastro8, 4, '0') || '.' || LPAD(pianoconti.soco8, 6, '0') || ' ' || pianoconti.nome8_1 contoContr, tbl_0008.prefi8 || '.' || LPAD(tbl_0008.mastro8, 4, '0') || '.' || LPAD(tbl_0008.soco8, 6, '0') || ' ' || tbl_0008.nome8_1 || ' ' || tbl_0008.nome8_2 || ' ' || tbl_0008.via8_1 || ' ' || tbl_0008.loca8_1 contoCliPrincipale, (ccde9 || ' ' || decode(tbl_0210.testo210,null,'',tbl_0210.testo210)) ccde9 , COCP10 cocp, numdo210 numdo, datad210 datad, DECODE(dav210, 'D', impe210, 0.00 ) dare, DECODE(dav210, 'A', impe210, 0.00 ) avere FROM tbl_0010, tbl_0210, tbl_0009, tbl_0008, tbl_0008 pianoconti WHERE datar10 BETWEEN TO_DATE('01-01-2007','dd-mm-yyyy') AND TO_DATE('31-12-2007','dd-mm-yyyy') AND id10 = tbl_0210.id210 and tbl_0210.coso210 between 10230000100 and 10230001000 AND tbl_0008.coso8(+) = tbl_0210.coso210 AND pianoconti.coso8(+) = conc210 AND cccg9 = caus210 and tipo9 in (1, 2) ) principale ORDER BY codiceconto ,datareg ,protocollo
    I do this on different schema because the customer have one database with 2 factory schemas

  • Different query view format not shown

    Dear Gurus,
      I am kinda new to WAD; Here I made 2 different query views(Different format) and used 'Query View Selection' in WAD. But somehow, when i choose different query views from the drop down list, the format of the result all seem to be the same(as the first chosen one). Is there any setting that i might have missed out?
      And here is another question, can i possibly fill 'Query view selection' from different Query? and how to do that ?
    It's quite urgent for me, please help out ASAP.
    Thanks a lot~~ Points will be rewarded~~
    Charlie Lin

    In the property of the drop down box, you should have property called affected area, in that select both the query views you want to see and you should see different result as you change the drop down box.
    And also make sure your data provider for both of the views are different, need to create a new for the next one.
    thanks.
    Wond

Maybe you are looking for

  • Why are there many more glyphs available in Illustrator CS4 than Indesign CS4?

    I am in the process of converting a document from Illustrator to InDesign. Many of the glyphs and ligatures in Illustrator aren't available in Indesign for the same font, Bickham Script Pro. I checked that all of the opentype settings between the two

  • Java coding in combo box

    how to call the set of java coding by using combo box................

  • Java files question

    Hi I recently downloaded and installed the sql developer version 1.5. I am very happy that i can now see the java classes that have been loaded into the database. I want to know if there is a way i could change the way the files are listed, as in the

  • When I try to sync my I phone is not visable in Itunes,

    When I try to sync my I phone it does not show up in Itune or my computor I have tried everything

  • SQL Error while allocating Products

    I had a recipe by which I have created about 300 batches. For about 12-13 batches during product line allocation it takes the lot number & shows allocated qty. in Actual Qty. But while saving it shows an error " SQL Error User-Defined Exception : Err