Passing string to a cursor as parameter

Hi,
need some help
Version:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
DECLARE
     lv_dept VARCHAR2(100);
     Currec EMP%ROWTYPE;
     Cursor Cur_Dept(pv_dept VARCHAR2) IS SELECT * FROM EMP WHERE to_char(deptno) IN (pv_dept);
BEGIN
   lv_dept:='''10'''||','||'''20''';
      OPEN Cur_Dept(lv_dept);
   LOOP
        FETCH Cur_Dept INTO Currec;
                 Message(Currec.Ename||Currec.deptno); --Forms code
      EXIT WHEN Cur_Dept%NOTFOUND;     
   END LOOP;
   close Cur_Dept;
END;     
If I pass the parameter as a string , it doesn't work.
Regards,
Lokanath

As others have said, you should avoid using dynamic SQL.
As SQL running in SQL*Plus, something like this...
SQL> ed
Wrote file afiedt.buf
  1  select *
  2  from emp
  3  where deptno in (
  4                  with t as (select '&dept_numbers' as txt from dual)
  5                  select REGEXP_SUBSTR (txt, '[^,]+', 1, level)
  6                  from t
  7                  connect by level <= length(regexp_replace(txt,'[^,]*'))+1
  8*                )
SQL> /
Enter value for dept_numbers: 10,20
old   4:                 with t as (select '&dept_numbers' as txt from dual)
new   4:                 with t as (select '10,20' as txt from dual)
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
      7369 SMITH      CLERK           7902 17/12/1980 00:00:00        800                    20
      7566 JONES      MANAGER         7839 02/04/1981 00:00:00       2975                    20
      7782 CLARK      MANAGER         7839 09/06/1981 00:00:00       2450                    10
      7788 SCOTT      ANALYST         7566 19/04/1987 00:00:00       3000                    20
      7839 KING       PRESIDENT            17/11/1981 00:00:00       5000                    10
      7876 ADAMS      CLERK           7788 23/05/1987 00:00:00       1100                    20
      7902 FORD       ANALYST         7566 03/12/1981 00:00:00       3000                    20
      7934 MILLER     CLERK           7782 23/01/1982 00:00:00       1300                    10
8 rows selected.Or in PL/SQL, based on the same SQL...
SQL> ed
Wrote file afiedt.buf
  1  declare
  2    cursor cur_emps(p_deptnos in varchar2) is
  3      select *
  4      from emp
  5      where deptno in (
  6                       select REGEXP_SUBSTR (p_deptnos, '[^,]+', 1, level)
  7                       from dual
  8                       connect by level <= length(regexp_replace(p_deptnos,'[^,]*'))+1
  9                      );
10  begin
11    for e in cur_emps('10,20')
12    loop
13      dbms_output.put_line(e.empno||' - '||e.ename||' : '||e.deptno);
14    end loop;
15* end;
SQL> /
7369 - SMITH : 20
7566 - JONES : 20
7782 - CLARK : 10
7788 - SCOTT : 20
7839 - KING : 10
7876 - ADAMS : 20
7902 - FORD : 20
7934 - MILLER : 10
PL/SQL procedure successfully completed.
SQL>

Similar Messages

  • How to pass multiple query string values using the same parameter in Query String (URL) Filter Web Part

    Hi,
    I want to pass multiple query string values using the same parameter in Query String (URL) Filter Web Part like mentioned below:
    http://server/pages/Default.aspx?Title=Arup&Title=Ratan
    But it always return those items whose "Title" value is "Arup". It is not returned any items whose "Title" is "Ratan".
    I have followed the
    http://office.microsoft.com/en-us/sharepointserver/HA102509991033.aspx#1
    Please suggest me.
    Thanks | Arup
    THanks! Arup R(MCTS)
    SucCeSS DoEs NOT MatTer.

    Hi DH, sorry for not being clear.
    It works when I create the connection from that web part that you want to be connected with the Query String Filter Web part. So let's say you created a web part page. Then you could connect a parameterized Excel Workbook to an Excel Web Access Web Part
    (or a Performance Point Dashboard etc.) and you insert it into your page and add
    a Query String Filter Web Part . Then you can connect them by editing the Query String Filter Web Part but also by editing the Excel Web Access Web Part. And only when I created from the latter it worked
    with multiple values for one parameter. If you have any more questions let me know. See you, Ingo

  • How can I pass an empty array to a parameter of type PLSQLAssociativeArray

    How can I pass an empty array to a parameter of type PLSQLAssociativeArray in VB? I defined the parameter like this
    Dim myArray() as String = new String() {}
    Dim myPara as new Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray
    myPara = 0
    myPara.Value = myArray
    When I execute my stored procedure giving the above parameter, I got error saying OracleParameter.Value is invalid.
    I have tried to give it the DBNull.Value, but it doesn't work either.
    Note: everything works fine as long as myArray has some item in there. I just wonder how I can make it works in case I have nothing.
    Thank you,

    How can I pass an empty array to a parameter of type PLSQLAssociativeArray in VB? I defined the parameter like this
    Dim myArray() as String = new String() {}
    Dim myPara as new Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray
    myPara = 0
    myPara.Value = myArray
    When I execute my stored procedure giving the above parameter, I got error saying OracleParameter.Value is invalid.
    I have tried to give it the DBNull.Value, but it doesn't work either.
    Note: everything works fine as long as myArray has some item in there. I just wonder how I can make it works in case I have nothing.
    Thank you,

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

  • Problem with prepared statement where cluase when passing string value.Help

    I am updating a table using the following code. I am using string parameter in where clause. if I use Long parameter in where clause with ps.setLong , this code is working. Is there any special way to pass string value? Am I doing anything wrong?
    ===================
    updateMPSQL.append("UPDATE MP_Table SET ");
         updateMPSQL.append("MPRqmt = ?,End_Dt = ? ");
              updateMPSQL.append("where POS = ? ");
              System.out.println(updateMPSQL.toString());
              con     = getConnection(false) ;
              ps      = con.prepareStatement(updateMPSQL.toString());
              ps.setLong(1,MPB.getMPRqmt());
              ps.setDate(2,MPB.getEnd_Dt());
              ps.setString(3,MPB.getPos());
    result = ps.execute();
              System.out.println("Result : " + result);
    ==========
    Please help me.
    Thanks in advance.
    Regards,
    Sekhar

    doesn't Pos look like a number rather than a string variable?
    if I use Long
    parameter in where clause with ps.setLong , this code
    is working.
    updateMPSQL.append("where POS = ? ");
    ps.setString(3,MPB.getPos());

  • Passing a Vector object as a parameter to a method

    Hi,
    How can I pass a Vector object as a parameter to a method?
      void buttonAdd_actionPerformed(ActionEvent e) {
        Vector studentHobbies = new Vector();
          String[] items = listHobbies.getSelectedItems();
          for (int i=0; i<items.length; i++) {
            studentHobbies.addElement(items);
    newStudent = new Student(Name,StudentNumber,studentHobbies);
    studentenlist.addTo(newStudent);
    So I want to pass the Vector object 'studentHobbies'  to a method.
    Would I do something like this :import java.util.Vector;
    public Student(String Name, int StudentenNumber, Vector studentHobbies){
    this.Name = Name;
    this.StudentNumber = StudentNumber;
    this.studentHobbies = StudentenHobbies;

    yes, thats how you do it.
    maybe you should first try your idea and then ask people questions?
    also, use ArrayList instead of Vector, its better - google as to why if you care.

  • Passing different tables as a input parameter

    HI,
    I've 5 tables TAB1, TAB2, TAB3, TAB4, TAB5
    and I created 5 store procedures to generate 5 file.txt with utl_file utility.
    Now I'd like to know if possible create just one stored procedure (or package) with just one cursor
    that passing different tables as a input parameter.
    Have you any idea?
    Thanks in advance!

    Here you go...
    SQL> create table tab1 as select 1 as x, 'A' as y from dual union
      2                       select 2, 'B' from dual union
      3                       select 3, 'C' from dual;
    Table created.
    SQL>
    SQL> create table tab2 as select 4 as x, 'D' as y from dual union
      2                       select 5, 'E' from dual union
      3                       select 6, 'F' from dual;
    Table created.
    SQL>
    SQL> CREATE OR REPLACE PROCEDURE output_tbl (p_table_name IN VARCHAR2) IS
      2    v_cur     SYS_REFCURSOR;
      3    x         NUMBER;
      4    y         VARCHAR2(10);
      5  BEGIN
      6    OPEN v_cur FOR 'SELECT x, y FROM '||p_table_name||' ORDER BY x';
      7    LOOP
      8      FETCH v_cur INTO x, y;
      9      EXIT WHEN v_cur%NOTFOUND;
    10      -- Here you would output to your file, but for ease of
    11      -- demonstration I'll just dbms_output the data
    12      DBMS_OUTPUT.PUT_LINE(x||' : '||y);
    13    END LOOP;
    14  END;
    15  /
    Procedure created.
    SQL> exec output_tbl('TAB1');
    1 : A
    2 : B
    3 : C
    PL/SQL procedure successfully completed.
    SQL> exec output_tbl('TAB2');
    4 : D
    5 : E
    6 : F
    PL/SQL procedure successfully completed.
    SQL>

  • Pass an array of buttons by parameter

    Dear Java developers :
    I am asking about how can I pass an array of JButton by parameter.
    For example, I have a method that randomly picks a button that have an empty text (""), if not empty then the method recursively calls herself and so on until it finds an empty labeled button :
    private void randomPick(JButton buttons[]) {
              Random r = new Random();
              int n = r.nextInt(8);
              if (buttons[n].getText()!="") {
                   countClicks--;
                   randomPick(buttons[n]);
              } else {
                   buttons[n].setText("O");
                   buttons[n].setEnabled(false);
              countClicks++;
         }The problem is that I don't know neither how to pass the buttons[] in parameter of a method nor how to write the calling of the method properly.
    Thanks for your help,
    Hassanova.

    Ok sorry for my explanations I'll try to be more clear :
    I have 2 classes at this point : one that draws the interface, the other makes the treatment
    here is the 1st class :
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    public class TTTGameJFrameView implements ActionListener {
         JFrame frame = null;
         JButton buttons[] = new JButton[10];
         public TTTGameJFrameView() {
              setView();
         public void setView() {
              // Building the window
              frame = new JFrame("Tic Tac Toe Game");
              frame.setSize(300,300);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setLayout(new GridLayout(3,3));
              //Positioning the buttons
              for(int i = 0; i<=8; i++){
                   buttons[i] = new JButton();
                   frame.add(buttons);
                   buttons[i].addActionListener(this);
         public void close() {
              frame.dispose();
         public void display() {
              frame.setVisible(true);
         @Override
         public void actionPerformed(ActionEvent e) {
              // TODO Auto-generated method stub
    And here is the 2nd class where I don't know how to pass by parameter the buttons declared in the 1st class to the methods and hpw to call them properly....
    package test.TicTacToe;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Random;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    public class TTTGameModel {
         JButton buttons[] = new JButton[10];
         JFrame frame = null;
         JButton buttons[] = new JButton[10];
         private void setView() {
              // Building the window
              frame = new JFrame("Tic Tac Toe Game");
              frame.setSize(300,300);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setLayout(new GridLayout(3,3));
              //Positioning the buttons
              for(int i = 0; i<=8; i++){
                   buttons[i] = new JButton();
                   frame.add(buttons);
                   buttons[i].addActionListener(this);
              frame.setVisible(true);
         private int[][] winPositions = new int[][] {
                   {0,1,2}, {3,4,5}, {6,7,8},
                   {0,3,6}, {1,4,7}, {2,5,8},
                   {0,4,8}, {2,4,6}
         private int countClicks = 0;
         private boolean win = false;
         private String buttonLetter = "";
         private String xOrO = "";
         public void actionPerformed(ActionEvent e, JButton buttons[]) {
              for(int i=0; i<=8; i++) {
                   if(e.getSource().equals(buttons[i])) {
                        buttons[i].setText("X");
                        buttons[i].setEnabled(false);
              if ((countClicks <= 8) && (win==false)) {
                   randomPick(buttons);
                   countClicks++;
                   whoWins(buttons);
                   System.out.println("click�");
              //System.out.println(countClicks);
         private void whoWins(JButton buttons[]) {
              for (int i=0; i<=7; i++) {
                   if (buttons[winPositions[i][0]].getText().equals(buttons[winPositions[i][1]].getText()) &&
                        buttons[winPositions[i][1]].getText().equals(buttons[winPositions[i][2]].getText()) &&
                        buttons[winPositions[i][0]].getText()!="")
                        win = true;
              System.out.println(countClicks + " " + win);
              showWinner(win,countClicks);
         private void showWinner(boolean isWin, int count) {
              if(count % 2 == 0)
                   xOrO = "O";
              else
                   xOrO = "X";
              if (isWin == true){
                   JOptionPane.showMessageDialog(null,"The "+xOrO+" Player Wins!");
                   System.exit(0);
              else if ((isWin == false) && (count >= 9)){
                   JOptionPane.showMessageDialog(null,"Draw Game");
                   System.exit(0);
         private void buttonClick(ActionEvent e) {
         private void randomPick(JButton buttons[]) {
              Random r = new Random();
              int n = r.nextInt(8);
              if (buttons[n].getText()!="") {
                   countClicks--;
                   randomPick(buttons[n]);
              } else {
                   buttons[n].setText("O");
                   buttons[n].setEnabled(false);
              countClicks++;
         private void randomPick(JButton button) {
              // TODO Auto-generated method stub
         public static void main(String[] args) {
              TTTGameJFrameView tt = new TTTGameJFrameView();
              tt.setView();
              tt.display();
    Thank you very much I appriciate your patience !
    Hassanova.

  • URGENT!!passing variables to ref-cursor stored procedures

    I have build forms6 block base ona stored procedures with ref
    cursor.
    But....it's impossible to pass variables from block.item to
    in-out parameter of ref cursor..to make a where clause for
    example!!
    I've tried all..but nothing happens..
    Can someone help me?
    Thanks..
    null

    Manish Wadhwa (guest) wrote:
    : Gigi (guest) wrote:
    : : I have build forms6 block base ona stored procedures with ref
    : : cursor.
    : : But....it's impossible to pass variables from block.item to
    : : in-out parameter of ref cursor..to make a where clause for
    : : example!!
    : : I've tried all..but nothing happens..
    : : Can someone help me?
    : : Thanks..
    : >>
    : It is not possible to send values as parameter to the stored
    : procedure because, oracle uses the trigger query-procedure for
    : calling the stored procedure and it does not entertain any
    : changes to that trigger. This is a problem with block based on
    : stored procedure, we have also tried it with table of records
    : instead of ref cursor, but doesn't work.
    : Manish
    Thanks Manish..
    i was afraid about that..
    But ..i ask to myself(retoric question..) it's possible the
    development oracle team build a "black box" like a stored
    procedure with ref o table of records who permit to select
    million of records in few second( i selected 5 million of records
    in 2 seconds..) and cannot permit to passing variables to these
    cursor.. every end users production forms must be working in
    this way..I don't understand..
    Gigi
    null

  • Cursor c1 parameter valve (PAR_SPRIDEN_PIDM) into the cursor c2

    hi,
    I am using 10g. I am new to oracle.
    My task is:
    I have to pass cursor c1 parameter valve (PAR_SPRIDEN_PIDM) into the cursor c2
    and get the output FULL_NAME which Concatenate the first_name and last_name
    Please find the code:
    ========================================
    CREATE TABLE spriden
    ( SPRIDEN_PIDM NUMBER(8
    ,SPRIDEN_ID VARCHAR2(9)
    ,SPRIDEN_LAST_NAME VARCHAR2(60)
    ,SPRIDEN_FIRST_NAME VARCHAR2(60 CHAR)
    ,SPRIDEN_CHANGE_IND VARCHAR2(1)
    ==================================================
    create or replace procedure multiple_cursors_proc is
    cursor c1 (PAR_SPRIDEN_PIDM in SPRIDEN.SPRIDEN_PIDM%type) is
    select SPRIDEN_ID
    from SPRIDEN
    where SPRIDEN_CHANGE_IND IS NULL
    and SPRIDEN_PIDM = PAR_SPRIDEN_PIDM;
    cursor c2 is select (SPRIDEN_FIRST_NAME || ' ' || SPRIDEN_LAST_NAME) FULL_NAME
    from SPRIDEN
    where SPRIDEN_CHANGE_IND IS NULL
    and SPRIDEN_PIDM = PAR_SPRIDEN_PIDM;
    BEGIN
    FOR cr1 in c1
    loop
    for cr2 in c2
    loop
    DBMS_OUTPUT.PUT_LINE('START TIME : ' ||
    to_char(sysdate, 'HH24:MI:SS'));
    dbms_output.put_line('SPRIDEN_PIDM: ' || PAR_SPRIDEN_PIDM || ' ' ||
    'FULL_NAME: ' || cr2.FULL_NAME);
    DBMS_OUTPUT.PUT_LINE('END TIME : ' ||
    to_char(sysdate, 'HH24:MI:SS'));
    end loop;
    end loop;
    end multiple_cursors_proc;
    =========================================================
    Thanks in advance
    Edited by: user10285804 on Apr 14, 2011 5:57 PM

    Hi,
    Your code has to change this way (untested):
    create or replace procedure multiple_cursors_proc is
    cursor c1 (PAR_SPRIDEN_PIDM in SPRIDEN.SPRIDEN_PIDM%type) is
    select SPRIDEN_ID
    from SPRIDEN
    where SPRIDEN_CHANGE_IND IS NULL
    and SPRIDEN_PIDM = PAR_SPRIDEN_PIDM;
    cursor c2(PAR_SPRIDEN_ID SPRIDEN.SPRIDEN_ID%type)
    is
      select (SPRIDEN_FIRST_NAME || ' ' || SPRIDEN_LAST_NAME) FULL_NAME
      from SPRIDEN
      where SPRIDEN_CHANGE_IND IS NULL
      and SPRIDEN_PIDM = PAR_SPRIDEN_ID;
    BEGIN
    FOR cr1 in c1
    loop
      for cr2 in c2(cr1.SPRIDEN_ID)
      loop
        DBMS_OUTPUT.PUT_LINE('START TIME : ' ||to_char(sysdate, 'HH24:MI:SS'));
        dbms_output.put_line('SPRIDEN_PIDM: ' || PAR_SPRIDEN_PIDM || ' ' ||'FULL_NAME: ' || cr2.FULL_NAME);
        DBMS_OUTPUT.PUT_LINE('END TIME : ' ||to_char(sysdate, 'HH24:MI:SS'));
      end loop;
    end loop;
    end multiple_cursors_proc;Herald ten Dam
    http://htendam.wordpress.com

  • Passing String Which Has Single Quote Row/Value to a Function Returns Double Quoate

    Hi, I'm getting weird thing in resultset. When I pass String which has single quote value in it to a split function , it returns rows with double quote. 
    For example  following string:
    'N gage, Wash 'n Curl,Murray's, Don't-B-Bald
    Returns:
    ''N gage, Wash ''n Curl,Murray''s, Don''t-B-Bald
    Here is the split function:
    CREATE Function [dbo].[fnSplit] (
    @List varchar(8000), 
    @Delimiter char(1)
    Returns @Temp1 Table (
    ItemId int Identity(1, 1) NOT NULL PRIMARY KEY , 
    Item varchar(8000) NULL 
    As 
    Begin 
    Declare @item varchar(4000), 
    @iPos int 
    Set @Delimiter = ISNULL(@Delimiter, ';' ) 
    Set @List = RTrim(LTrim(@List)) 
    -- check for final delimiter 
    If Right( @List, 1 ) <> @Delimiter -- append final delimiter 
    Select @List = @List + @Delimiter -- get position of first element 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    While @iPos > 0 
    Begin 
    -- get item 
    Select @item = LTrim( RTrim( Substring( @List, 1, @iPos -1 ) ) ) 
    If @@ERROR <> 0 Break -- remove item form list 
    Select @List = Substring( @List, @iPos + 1, Len(@List) - @iPos + 1 ) 
    If @@ERROR <> 0 Break -- insert item 
    Insert @Temp1 Values( @item ) If @@ERROR <> 0 Break 
    -- get position pf next item 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    If @@ERROR <> 0 Break 
    End 
    Return 
    End
    FYI: I'm getting @List value from a table and passing it as a string to split function.
    Any help would be appreciated!
    ZK

    fixed the issue by using Replace function like
    Replace(value,'''''','''')
    Big Thanks Patrick Hurst!!!!! :)
    Though I came to another issue which I posted here:
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/a26469cc-f7f7-4fb1-ac1b-b3e9769c6f3c/split-function-unable-to-parse-string-correctly?forum=transactsql
    ZK

  • Passing ALL values to a single parameter

    In Bi Publisher Report, I need to pass 'ALL' values to a single parameter
    Here is brief explanation about my requirement,
    I have 3 parameters
    Parameter A,
    Parameter B,
    Parameter C
    I have to pass ALL values to last parameter i.e; Parameter C and the rest should pass only single value, how should I do that?
    Any help would be greatly appreciated.
    Thank you

    Hi,
    have a look here: http://www.oracle.com/global/de/community/bip/tipps/dynamische_queries/index_en.html
    This might give you an idea how to work with multi-value parameters.
    Regards
    Rainer

  • Problem in using String in Implicit Cursor

    Hi,
    I am facing problem in using String in Implicit Cursor:
    I have initialise
    DECLARE
    v_grant varchar2(4000);
    begin
    v_grant:='SELECT TABLE_NAME FROM DUMP_USER_TABLES WHERE TABLE_NAME LIKE ';
    FOR obj IN (SELECT v_grant||'''BS%''' FROM dual) LOOP
    V_REVOKE:='REVOKE ALL ON ' || 'obj.TABLE_NAME' || ' FROM ' || '''TEST''';
    DBMS_OUTPUT.PUT_LINE('THE REVOKE STATEMENT IS'||V_REVOKE);
    num := num + 1;
    END LOOP;
    END;
    I am not getting the value from obj.TABLE_NAME its coming as 'obj.TABLE_NAME'
    Kindly anyhelp will be needful for me

    Besides from what Sybrand already pointed out clearly:
    Your example doesn't run at all:
    MHO%xe> DECLARE
      2  v_grant varchar2(4000);
      3  begin
      4  v_grant:='SELECT TABLE_NAME FROM DUMP_USER_TABLES WHERE TABLE_NAME LIKE ';
      5  FOR obj IN (SELECT v_grant||'''BS%''' FROM dual) LOOP
      6  V_REVOKE:='REVOKE ALL ON ' || 'obj.TABLE_NAME' || ' FROM ' || '''TEST''';
      7  DBMS_OUTPUT.PUT_LINE('THE REVOKE STATEMENT IS'||V_REVOKE);
      8  num := num + 1;
      9  END LOOP;
    10  END;
    11  /
    V_REVOKE:='REVOKE ALL ON ' || 'obj.TABLE_NAME' || ' FROM ' || '''TEST''';
    FOUT in regel 6:
    .ORA-06550: line 6, column 1:
    PLS-00201: identifier 'V_REVOKE' must be declared
    ORA-06550: line 6, column 1:
    PL/SQL: Statement ignored
    ORA-06550: line 7, column 49:
    PLS-00201: identifier 'V_REVOKE' must be declared
    ORA-06550: line 7, column 1:
    PL/SQL: Statement ignored
    ORA-06550: line 8, column 1:
    PLS-00201: identifier 'NUM' must be declared
    ORA-06550: line 8, column 1:
    PL/SQL: Statement ignoredI guess you need to read up on quoting strings properly and probably also dynamic SQL.
    But:
    WHAT are you trying to do anyway?
    I cannot parse your code at all...so what is your requirement in human language?

  • Failure using {CALL } syntax & passing string params w/ # (hash)

    We are experiencing a problem calling functions using the {CALL } syntax and passing string parameters that contain # (hash) symbols. Apparently, something interprets the # inside the string literal and fails the call.
    We use this syntax with procedure calls from a Java applet to an Oracle 8i database using the 8.1.6.2.0 ODBC Oracle driver. The applet is running under the Java 1.3.1 plug-in and we are using a third party JDBC, type III, driver from JDataConnect to link the applet to the Oracle ODBC driver.
    Any insight on this would be greatly appreciated.

    What's the result of con.getAutoCommit()?
    You might try con.setAutoCommit(true) to see if that sorts it.
    /k1

  • Pass a ViewObject as a data parameter into Oracle Reports

    Can I pass a ViewObject as a data parameter in an Oracle Reports jsp Report?

    you can use impliment this script to your query get data from file
    function AfterPForm return boolean is
    infile text_io.file_type;
    linebuf varchar2(3000) := '';
    filename varchar2(100);
    v_employee_id varchar2(2000);
    begin
    filename := :P_file_name; /* you can pass the file name like this c:\temp\test.txt */
    infile := text_io.fopen(filename,'r');
    loop
    text_io.get_line(infile,linebuf);
    v_employee_id := v_employee_id&#0124; &#0124;linebuf&#0124; &#0124;' ';
    end loop;
    if text_io.is_open(infile) then
    text_io.fclose(infile);
    end if;
    exception when no_data_found then
    text_io.fclose(infile);
    v_employee_id := replace(rtrim(v_employee_id),' ',',');
    :p_employee_param := 'and employee_id in ('&#0124; &#0124;v_employee_id&#0124; &#0124;')';
    /* you can use either 'where employee_id in ('&#0124; &#0124;v_employee_id&#0124; &#0124;')' or
    'and employee_id in ('&#0124; &#0124;v_employee_id&#0124; &#0124;')' */
    return (TRUE);
    end;
    I think it will help you to solve your problem. Do not forget to put &v_employee_param
    Good Luck
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by gvardhan:
    The file will have one EmployeeID per line as follows
    100
    200
    ...<HR></BLOCKQUOTE>
    null

Maybe you are looking for