Simple select stmt in Procedure (?) - with example

I am having problems getting the following code example to work.
CREATE OR REPLACE PROCEDURE Portdev.Show_One_Record
v_record_question quiz.quest_num%ROWTYPE
AS
BEGIN
CURSOR c_records IS
-- will get all records ordered randomly, matching category as passenger
SELECT * FROM PORTDEV.QUIZ ORDER BY dbms_random.value where CATEGORY=passenger;
BEGIN
FOR v_record_question IN c_records LOOP
DBMS_OUTPUT.PUT_LINE(v_record_question.quest_num);
END LOOP;
END Portdev.Show_One_Record;
I get the error message
Error: Line No. 1 : PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
( ; is with authid deterministic parallel_enable as compress
compiled wrapped
(WWV-17050)
ORA-24344: success with compilation error (WWV-11230)
Any help would be greatly received.
Eddie

If your procedure in the Package you don't need
CREATE OR REPLACE, just PROCEDURE

Similar Messages

  • In Scom,How to add CAC value in given MP (management pack)? Please give me in detail procedure with example if possible.

    In Scom,How to add CAC value in given MP (management pack)? Please give me in detail procedure with example if possible.

    Hi 
    CAC is System.ConsolidatorCondition condition detection module used to consolidate the monitoring i.e. you can generate an alert on multiple occurrence of issues instituted of generating single alert for issue.
    refer below link for more information
    http://msdn.microsoft.com/en-us/library/ee809324.aspx
    http://social.technet.microsoft.com/wiki/contents/articles/20301.how-to-add-consolidation-for-url-monitoring-in-scom-20072012.aspx
    Regards
    sridhar v

  • Sales Information System Procedure with example

    Hi Experts,
    i need some documents or notes on the Logistics Information System (Specially Sales Information System) procedure wth some example.
    my mail id :  <REMOVED>
    Thanks in advance
    raj
    Message was edited by:
            Yathish K

    Hi,
    Please <b>read the rules of engagement</b> before posting.
    <b>- Do not ask to send you an email.</b>
    The question you ask and the solution to it is often also interesting for other users of the community. If you ask somebody to send you the answer per email, you deprive others of also learning to know the answer. Therefore any requests for sending material or answers to an email address will be modified by the forum moderators.

  • Use of Select stmts with Update stmts

    Hi,
    I want to execute the following update stmt...
    UPDATE Test1_tab a
    SET a.invpln_seq_no = (SELECT b.seq_no
    FROM Test2_tab b
    WHERE b.contract_id = a.contract_id
    AND b.date_from = a.period_from_date)
    WHERE a.invpln_seq_no != (SELECT b.seq_no
    FROM Test2_tab b
    WHERE b.contract_id = a.contract_id
    AND b.date_from = a.period_from_date)
    Here the problem is I have used 'SELECT b.seq_no FROM Test2_tab b WHERE b.contract_id = a.contract_id AND b.date_from = a.period_from_date' twice, one in the SET clause and the other one in WHERE clause...But it is the same SELECT stmt...So this same Select stmt runs twice when I run the whole update stmt I guess. Is there a way to do the above update, where it runs the SELECT stmt only once...
    Any input is highly appreciated...
    Thanks And Best Regards,
    /Dinesh...

    Then you can use Merge statement instead.
    try this
    merge into test1_tab t1
    using
    (SELECT a.rowid,b.seq_no SEQ_DEST
    FROM test1_tab a,test2_tab b
    WHERE b.contract_id = a.contract_id
    AND  b.date_from = a.period_from_date
    AND a.invpln_seq_no != b.seq_no) t2
    ON (t1.rowid=t2.rowid)
    WHEN MATCHED THEN
    UPDATE SET t1.invpln_seq_no=t2.seq_destor if you are sure that sno is a unique key with out any duplicates and if you are going to perform one time manual update then you can use an undocumented hint /*+ bypass_ujvc */ to do this.
    *DO NOT include this code if you are about to add it in a production procedure or a function
    UPDATE /*+ bypass_ujvc */ (SELECT a.invpln_seq_no SEQ_SRC,b.seq_no SEQ_DEST FROM test1_tab a,test2_tab  b
    WHERE b.contract_id = a.contract_id
    AND  b.date_from = a.period_from_date
    AND a.invpln_seq_no != b.seq_no)
    SET SEQ_SRC = SEQ_DESTRegards,
    Prazy

  • How do i include this 'select' stmt in a 'procedure'.

    create or replace procedure proc1
    AS
    BEGIN
    select table1.name,table1.symbol,table1.quantity,table2.price,(table1.quantity*table2.price) AS Total
    from table1,table2
    where table2.date=(select date from
    table2,table1,table3
    where table1.date=table3.date
    AND table1symbol=table2.symbol)
    END;
    here, name and symbol are varchar2
    and quantity and price are number
    date is date
    the main problem is tht select in a procedure requires an INTO clause
    The normal select query is running but i am unable to transform it into a procedure using variables and cursors
    can u solve this prob for me...??

    > The normal select query is running but i am unable to
    transform it into a procedure using variables and cursors
    There are a couple of ways to define cursors - even a plain SQL as what you have posted is a cursor.
    The details:
    Oracle® Database PL/SQL User's Guide and Reference
    Chapter 6. Performing SQL Operations from PL/SQL
    http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14261/toc.htm
    The basics - for an explicit cursor you want to use bulk collection 99% of the time in order for performance and scalability. So (assuming the SQL has been analysed and optimised):
    create or replace procedure proc1 as
    -- define an explicit cursor
    cursor myCursor is
    select
    table1.name,table1.symbol,table1.quantity,
    table2.price,(table1.quantity*table2.price) AS Total
    from table1,table2
    where table2.date=(
    select
    date
    from table2,table1,table3
    where table1.date=table3.date
    and table1.symbol=table2.symbol
    -- define an array type for fetching the rows into
    type TBuffer is table of myCursor%ROWTYPE;
    -- define an array for fetching the rows into
    buffer TBuffer;
    begin
    open myCursor;
    loop
    -- fetch a max of 1000 rows at a time
    fetch myCursor bulk collect into buffer limit 1000;
    -- process these rows
    for i in 1..buffer.Count
    loop
    -- buffer needs to be subscripted to get to the row,
    -- and buffer contains the columns that were selected
    -- from the tables, e.g.
    DBMS_OUTPUT.put_line( 'Processing '||buffer(i).name );
    Proc2( buffer(i) );
    end loop;
    exit when myCursor%NOTFOUND;
    end loop;
    close myCursor;
    end;
    All the details of bulk processing and cursors are in the PL/SQL User Guide - with examples.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Error in a Select with a second Select in stored procedure.

    Hi,
    Can you help me please to know why this query works in a PL/SQL Console but not in a stored procedure.
    Query :
    SELECT
    variable1,
    variable2,
    (SELECT sum(variables) FROM foo), <---- Error here
    FROM
    bar
    this query works in console but if i compile a stored procedure with this i have the error :
    Compilation errors for PACKAGE BODY INFOC.BSS
    Error: PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
    ( - + mod not null others <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> avg
    count current exists max min prior sql stddev sum variance
    execute forall time timestamp interval date
    <a string literal with character set specification>
    <a number> <a single-quoted SQL string>
    Line: 2804
    For information, i use Oracle 8 and PL/SQL Developer
    Thanks

    In earlier versions of Oracle (like 8) there are some differences between the SQL engine and the SQL engine in PL/SQL. Things that work in SQL may not work on PL/SQL. I can replicate your error in my 8.1.7.4 instance, but it works correctly in my 9.2 instance. I don't have anything in between to test, so I can't tell you which version it will work on.
    The workaround is to create a view in the database using the query, and query that view in your stored procedure.
    HTH
    John

  • Problem with SImple Select Query

    Hi
    I am trying to write a simple Select SQL to a table and find out whether certain data exist or not. I have done this before but now for some reason this one is not working.
    I started like this
    select single * from ANLH where ANLN1 = rec-Asset
                                                 and BUKRS = Comp_Cd.
    * Error Handler for non-existent empno in the database
      if sy-subrc = 0 or rec-asset = ''.
         rec_failed = 'T'.
         concatenate 'Asset does not exist' rec-asset into asst_err.
      endif.
    when i debugged the code i found out that sy-subrc  is returning 4 all the time. (i have passes some numbers in rec-Asset which i know doesn't exist in that table.
    So i have modified the code to see if its pulling anything.
    like this
    select single ANLN1 into v_Asset from ANLH where ANLN1 = rec-Asset
                                                 and BUKRS = Comp_Cd.
    * Error Handler for non-existent empno in the database
      if sy-subrc = 0 or rec-asset = ''.
         rec_failed = 'T'.
         concatenate 'Asset does not exist' rec-asset into asst_err.
      endif.
    in debug v_asset is always empty (for real number and for the madeup number)
    Please help.
    Thanks
    Edited by: Anwarul Kabir on Apr 3, 2008 9:27 PM
    Edited by: Anwarul Kabir on Apr 3, 2008 9:29 PM
    Edited by: Anwarul Kabir on Apr 3, 2008 9:30 PM

    Thanks for the answer. But i thought i was doing the same. Anyway I replaced my code with yours but result is the same. I also did this
    select single
    ANLN1 into v_Asset
    from ANLH where
    ANLN1 = '20000544'
    and BUKRS = '3000'.
    I did SE11 and entered the table name and i can see that data.
    but on my code i get sy-subrc=4 and v_Asset is blank
    again i tried with this madeup number which i know its not in the table
    select single
    ANLN1 into v_Asset
    from ANLH where
    ANLN1 = '2056555433544'
    and BUKRS = '3000'.
    Get sy-subrc=4 and v_Asset is blank...
    Is there anything special about the Table?

  • Standard Match Code for Selection Options with Example

    Hi Guys,
                 Can anybody tell me Standard Match Code or Search help for Selection Options.
             ex: MBEW-MATNR , MBEW-BWKEY and MBEW-BWTAR. can anybody tell how to keep Search Help or Match Code for the Above Fields in ECC 6.0 with Example
              Very Urgent.
    Thanks,
    Gopi.

    Well Gopi.. as per your requirement no need to use collective search help.
    I guess you have three fields in selection-screen,out 3 fields you have two fields contains search help.
    Create your user defined search help BWTAR ..
    Check the below links for creation search help :
    http://help.sap.com/saphelp_46c/helpdata/EN/cf/21ee2b446011d189700000e8322d00/frameset.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/41/f6b237fec48c67e10000009b38f8cf/content.htm
    Hope you got it.
    Thanks
    Seshu

  • Error  with select stmt.

    Hi All,
    I am getting this error , can you please tell me what I am doing wrong with the select stmt.
    SELECT AFKDAT ANETWR B~KZWI1
                         FROM VBRK AS A INNER JOIN VBRP AS B ON
                              AVBELN = BVBELN
                              INTO (IOUT-FKDAT, IOUT-NETWR, IOUT-KZWI1)
                              WHERE B~VBELN = IOUT-VBELV
                              AND   B~POSNR = ISDOC-POSNR.
    Incorrect nesting: Before the statement "ENDIF", the structure          
    introduced by "SELECT" must be concluded by "ENDSELECT". -
    Thanks
    Veni.

    Hi All,
    I tried INTO CORRESPONDING FIELDS OF IOUT
    but with this also same error is comming. I am sending part of code.
    Please help me.
    Thanks
    Veni.
    TABLES: VBAK, VBAP, KNA1, VBRK, VBRP, VBFA.
    DATA: BEGIN OF ISDOC OCCURS 0,
            VBELN LIKE VBAK-VBELN,
            POSNR LIKE VBAP-POSNR,
            KUNNR LIKE VBAK-KUNNR,
            ERDAT LIKE VBAK-ERDAT,
            BSTNK LIKE VBAK-BSTNK,
            MATNR LIKE VBAP-MATNR,
            ARKTX LIKE VBAP-ARKTX.
    DATA: END OF ISDOC.
    DATA: BEGIN OF IOUT OCCURS 0,
            VBELN LIKE VBAK-VBELN,
            POSNR LIKE VBAP-POSNR,
            KUNNR LIKE VBAK-KUNNR,
            NAME1 LIKE KNA1-NAME1,
            ERDAT LIKE VBAK-ERDAT,
            BSTNK LIKE VBAK-BSTNK,       
            MATNR LIKE VBAP-MATNR,
            ARKTX LIKE VBAP-ARKTX,
            VBELV LIKE VBRP-VBELN,
            FKDAT LIKE VBRK-FKDAT,
            NETWR LIKE VBRK-NETWR,
            KZWI1 LIKE VBRP-KZWI1.
    DATA: END OF IOUT.
    FORM getdata.
      SELECT A~VBELN B~POSNR A~KUNNR A~ERDAT A~BSTNK B~MATNR B~ARKTX
             FROM VBAK AS A INNER JOIN VBAP AS B ON A~VBELN = B~VBELN
             INTO TABLE ISDOC
             WHERE A~AUART IN SAUART
             AND A~ERDAT IN SERDAT
             AND A~KUNNR IN SKUNNR.
               SORT ISDOC BY VBELN POSNR.
      LOOP AT ISDOC.
        MOVE-CORRESPONDING ISDOC TO IOUT.
        CLEAR: KNA1.
        SELECT SINGLE * FROM KNA1 WHERE KUNNR = ISDOC-KUNNR.
        IF SY-SUBRC = 0.
          MOVE KNA1-NAME1 TO IOUT-NAME1.
        ENDIF.
        SELECT VBELN INTO IOUT-VBELV FROM VBFA WHERE VBELV = ISDOC-VBELN
                                               AND   POSNV = ISDOC-POSNR
                                               AND   VBTYP_N = 'O'.
          IF SY-SUBRC = 0.
            SELECT A~FKDAT A~NETWR B~KZWI1
                   FROM VBRK AS A INNER JOIN VBRP AS B ON A~VBELN = B~VBELN
                   INTO CORRESPONDING FIELDS OF IOUT
    *               (IOUT-FKDAT, IOUT-NETWR, IOUT-KZWI1)
                         WHERE B~VBELN = IOUT-VBELV
                         AND   B~POSNR = ISDOC-POSNR.
              APPEND IOUT.
              CLEAR IOUT.
            ENDIF.
          ENDLOOP.
        ENDFORM.                    " getdata

  • Dump with select stmt

    Hi All,
    Do you see anything wrong with this select stmt, it is giving me short dump.
    DATA: BEGIN OF it_output OCCURS 0,
          check TYPE c,
          vbeln LIKE likp-vbeln,
          lfdat LIKE likp-lfdat,
          kunnr LIKE likp-kunnr,
          knkli LIKE likp-knkli,
          netwr LIKE vbak-netwr,
          END OF it_output.
    SELECT LIKPVBELN LIKPLFDAT LIKPKUNNR LIKPKNKLI VBAK~NETWR
              FROM LIKP
              INNER JOIN VBAK ON LIKPVBELN = VBAKVBELN
              INTO TABLE IT_OUTPUT
              WHERE LIKP~LFDAT IN S_LFDAT
              AND LIKP~KUNNR IN S_KUNNR
              AND LIKP~LIFSK = P_LIFSK.
    Thanks
    Veni.

    Hi
    DATA: BEGIN OF it_output OCCURS 0,
    One error is here:
    <b>*check TYPE c,</b>
    vbeln LIKE likp-vbeln,
    lfdat LIKE likp-lfdat,
    kunnr LIKE likp-kunnr,
    knkli LIKE likp-knkli,
    netwr LIKE vbak-netwr,
    <b>check type c,</b>
    END OF it_output.
    SELECT LIKPVBELN LIKPLFDAT LIKPKUNNR LIKPKNKLI VBAK~NETWR
    FROM LIKP
    Another error is here
    <b>*INNER JOIN VBAK ON LIKPVBELN = VBAKVBELN</b>
    INNER JOIN LIPS ON LIKPVBELN = LIPSVBELN
    INNER JOIN VBAK ON LIPSVGBEL = VBAKVBELN
    INTO TABLE IT_OUTPUT
    WHERE LIKP~LFDAT IN S_LFDAT
    AND LIKP~KUNNR IN S_KUNNR
    AND LIKP~LIFSK = P_LIFSK.
    The link between sales order and delivery is in the item data, field is LIPS-VGBEL
    Max

  • Calling a stored procedure with a CLOB as input parameter

    Hello,
    I was unsuccessfully trying to call a stored procedure with a clob as input parameter from my C++ application using occi.
    Anyone got a working example to look at?
    I already checked the thread Invalid OCI handle when creating a Blob which didn't help.
    The problem seems to be that I don't have a lob locator to write my data (xml file) to. I tried creating a temporary clob using the sys.dbms_lob package which only resulted in a major headache on my part...
    I would appreciate any help.
    Kind regards
    Horst
    my environment:
    Visual Studio 2008, C++ application
    Oracle 11g

    To start using a blob you have to insert it into the database and then get it back. Sounds weird but that is how it is. Here is a very simple program to do this:
    #include<occi.h>
    #include <iostream>
    using namespace oracle::occi;
    using namespace std;
    int main()
      try
        Environment *env = Environment::createEnvironment(Environment::OBJECT);
        Connection *conn = env->createConnection("hr","hr","");
        string stmt1 = "insert into blob_tab values (:1) ";
        string stmt2 = "select col1 from blob_tab";
        Blob blob(conn);
        blob.setEmpty(conn);
        Statement *stmtObj = conn->createStatement(stmt1);
        stmtObj->setBlob(1,blob);
        stmtObj->executeUpdate();
        conn->commit();
        Blob blob1(conn);
        Statement *stmtObj2 = conn->createStatement(stmt2);
        ResultSet *rs = stmtObj2->executeQuery();
        while(rs->next())
         blob1 = rs->getBlob(1);
        string stmt3 = "begin my_proc(:1) ;end;";
        Statement *stmtObj3 =  conn->createStatement(stmt3);
        stmtObj3->setBlob(1,blob1);
        stmtObj3->executeUpdate();
      catch (SQLException e)
        cout << e.getMessage();
      /* The tables and procedure are primitive but ok for demo
        create table blob_tab(col1 blob);
        create or replace procedure my_proc(arg in blob)
        as
        begin
         -- just a putline here. you can do other more meaningful operations with the blob here
          dbms_output.put_line('hello');
       end;
    }Hope this helps.
    Thanks,
    Sumit

  • 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}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Calling ORACLE Store Procedure with parameters in user define function

    Hi everybody,
    We have a scenario connecting Oracle DB thru JDBC adapter.
    We have to call store procedure with input parameter and output parameter to retrieve data from DB. The implementation was made using JDBC adapter by building the correct XML message with EXECUTE action, and it works fine.
    Now we need to use DB lookup within mapping. I wrote users define function with SELECT statement (using the JDBC adapter) and it works fine but I need to call store procedure in ORACLE instead of SELECT statement.
    I found lot of examples concerning DB lookup but none of them explained how to write UDF calling store procedure in ORACLE with input and output parameters.
    I am looking for an example.
    Thanks in advance,
    Gigi

    I agree with you, but issue is we have lots of existing store procedure, which we need to call where damn required. I am sure those will be few but still i need to find out.
    If you think you are going to get existing MS Stored Procedures  or Oracle Packages that had nothing to do with the ORM previously to work that are not geared to do simple CRUD operations with the ORM and the database tables, you have a rude awakening
    coming that's for sure. You had better look into using ADO.NET and Oracle Command objects and call those Oracle Packages by those means and use a datareader.
    You could use the EF backdoor, call Oracle Command object and use the Packages,  if that's even possible, just like you can use MS SQL Server Stored Procedures or in-line T-SQL via the EF backdoor.
    That's about your best shot.
    http://blogs.msdn.com/b/alexj/archive/2009/11/07/tip-41-how-to-execute-t-sql-directly-against-the-database.aspx

  • Running SQL Procedure with dg4msql errors: Function sequence error HY010

    I am trying to execute a stored procedure on a SQL database and get the error Function sequence error HY010.
    A simple query on a table returns teh expected result.
    I have a single Win2008R2 server with MSSQL Express 2008 and Oracle 11gR2 (32bit not 64bit version of Oracle)
    Below is the gateway init, listener and tnsnames files and the query I am trying to run:
    -- initORIONWASP.ora --
    HS_FDS_CONNECT_INFO=INGRDB//waspForGIS
    HS_FDS_TRACE_LEVEL=OFF
    HS_FDS_RECOVERY_ACCOUNT=RECOVER
    HS_FDS_RECOVERY_PWD=RECOVER
    HS_CALL_NAME=dbo.spTest;dbo.spQueryAsset;dbo.spQueryAssetDetails
    HS_FDS_PROC_IS_FUNC=TRUE
    HS_FDS_RESULTSET_SUPPORT=TRUE
    -- Listener.ora -- (partial)
    (SID_DESC =
    (SID_NAME = ORIONWASP)
    (ORACLE_HOME = C:\Oracle\product\11.2.0\dbhome_1)
    (PROGRAM=dg4msql)
    -- tnsnames.ora -- (partial)
    ORIONWASP =
    (DESCRIPTION=
    (ADDRESS=(PROTOCOL=tcp)(HOST=INGRDB)(PORT=1521))
    (CONNECT_DATA=(SID=ORIONWASP))
    (HS=OK)
    -- Simple Query --
    Running select "Asset_ID" from asset@ORIONWASP; returns the correct result
    Running select * from sys.procedures@ORIONWASP; returns a list of procedures including the procedure I want to run
    -- This pl/sql block returns the error ******* identifier 'spTest@ORIONWASP' must be declared *******
    declare
    begin
    "spTest"@ORIONWASP;
    end;
    -- This passthrough pl/sql block returns ******** [Oracle][ODBC SQL Server Driver]Function sequence error {HY010} ********
    DECLARE
    CRS BINARY_INTEGER;
    RET BINARY_INTEGER;
    v_COL1 VARCHAR2(50);
    v_COL2 VARCHAR2(50);
    BEGIN
    CRS := DBMS_HS_PASSTHROUGH.OPEN_CURSOR@ORIONWASP;
    DBMS_HS_PASSTHROUGH.PARSE@ORIONWASP(CRS, 'exec spTest');
    BEGIN
    RET := 0;
    WHILE (TRUE)
    LOOP
    ret := DBMS_HS_PASSTHROUGH.FETCH_ROW@ORIONWASP(CRS, FALSE);
    DBMS_HS_PASSTHROUGH.GET_VALUE@ORIONWASP(CRS, 1, v_COL1);
    DBMS_HS_PASSTHROUGH.GET_VALUE@ORIONWASP(CRS, 2, v_COL2);
    DBMS_OUTPUT.PUT_Line('Col1:'||v_COL1||' Col2:'||v_COL2);
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    BEGIN
    DBMS_OUTPUT.PUT_LINE('End of Fetch');
    DBMS_HS_PASSTHROUGH.CLOSE_CURSOR@ORIONWASP(CRS);
    END;
    END;
    END;
    /

    The gateway configuration file contains:
    HS_FDS_PROC_IS_FUNC=TRUE
    HS_FDS_RESULTSET_SUPPORT=TRUE
    This setting commonly causes problems and you need to set
    HS_FDS_PROC_IS_FUNC=TRUE
    HS_FDS_RESULTSET_SUPPORT=FALSE
    for normal procedure calls and
    HS_FDS_PROC_IS_FUNC=FALSE
    HS_FDS_RESULTSET_SUPPORT=TRUE
    when calling the procedure with ref cursors.
    There's a note in My Oracle Support that gives you examples how to call remote SQl Server procedures
         Note.197192.1 Different Methods How To Call MS SQL Server Procedures Using TG4MSQL - DG4MSQL
    and another one for the Sybase gateway but this code is similar for the SQL Server:
    Article-ID: Note 351400.1
    Title: How to Call a Remote Sybase Procedure Using TG4SYBS

  • RE: Using BAPI in place of select stmt..

    Hi Experts,
    We alway use Select stmt to fetch the datas and display it, so is there any way to use available BAPI's  to select data and display the resultant output?if so can you given one simple example...

    1. Did you ever re-visited your queries
    Total Questions:  32 (30 unresolved) 
    I will suggest to close them by rewarding/answering with your solutions, if they are solved.
    2. Seeing your queries I dont think, you try to search the forum before posting a query. Start using it from today.
    3. Read rules of engagements before posting queries.
    Now for this one, if you search for BAPIs, their usage and their documentation you can understand this one by yourself.

Maybe you are looking for

  • Airport card is no longer reconised

    hi the guys and girls, basically i have have my laptop for more than 3 years now and it has worked seamlessly up until the last 6 months and just recently it has decided to not reconise the inbuilt Airport extreme card that was inbuilt at purchase (s

  • Facebook forms and action links like "untag" do not work in 3.6.8

    I upgraded to 3.6.8 last night, and now nothing on Facebook will work. If I try to post a status update or something on a friend's wall, the form doesn't automatically expand upon clicking in the box, and the submit button doesn't work. Also, when I

  • 1080i to 480p ?

    In an earlier post I had asked a question about taking 1080i source material and generating a letterboxed. progressive SD DVD. Straight forward enough, but the fellow that answered also warned that, by going to 480p as opposed to 480i, the resolution

  • Adobe reader for palm os?

    i was looking for acrobat reader for my clie sj22 but i come acoss so many programs i just wana ask what is the best free acrobat reader for my clie? also some good program to view word documents. and maybe suggestions on good program for viewing jpg

  • Photoshop Album error.

    Photoshop Album 1.0.50 now returns the following error:" Directx is installed , but could not be initialized". I have re-downloaded Visual Basic 6 but did not help. I have used Album for many years with great results. Any suggestions on possible caus