How to call the stored procedure when I press the button

Hello

I want to know how to call the procedure/SQL statement when I press the button using callable statement.

can someone give me it please link who knows the steps to do this.

Thanks in advance,
SAN

Hello

read this good example http://www.baigzeeshan.com/2010/05/calling-plsql-procedure-and-function-in.html

~ Abhijit

Tags: Java

Similar Questions

  • How to call a stored procedure in ADF

    How to call a stored procedure in the ADF (Jdev 11.1.1.6)?

    Code sample stored procedure:

    CREATE or REPLACE PROCEDURE SP_HELLOWORLD

    (

    NAME IN VARCHAR2

    OUT VARCHAR2 DESIRES

    ) AS

    BEGIN

    WISHES: = 'Hello'. name | ', Welcome to MS.';

    END SP_HELLOWORLD;

    Your Code of ADF is:

    try {}

    System.out.println ("* beginning of the code *");

    String sql = "start SP_HELLOWORLD(:NAME,:WISHES); end; ";

    CallableStatement st = getDBTransaction () .createCallableStatement (sql, getDBTransaction(). DEFAULT VALUE);

    st.setObject ("NAME", "ABC"); Replace with required param

    st.registerOutParameter ("WISHES", Types.VARCHAR); import java.sql.Types;

    St.Execute ();

    System.out.println ("the output of the function DB is:" + st.getObject ("WISHES"));

    System.out.println ("* end of code *");

    } catch (Exception e) {e.printStackTrace () ;}

  • Simple question-how to call a stored procedure or function of apex?

    Simple question-how to call a stored procedure or function of apex?
    Thanks advance.
    Doug

    Hi Doug,.
    You can call a procedure or function of apex. It depends on what you want to do with the function or procedure. If you want to retrieve table data in a specific area, you can try something like this-

    The following statement creates the function get_bal on the oe.orders of sample table (PL/SQL is in italics):

    CREATE FUNCTION get_bal (acc_no in NUMBER)
    RETURN NUMBER
    IS acc_bal NUMBER (11.2);
    BEGIN
    SELECT order_total
    IN acc_bal
    Orders
    WHERE customer_id = acc_no;
    Return (acc_bal);
    END;
    /

    The function created in the previous example can be used in a SQL statement. For example:

    SELECT get_bal (165) FROM DUAL;

    GET_BAL (165)
    ------------
    2519

    hope this will help,

    Kind regards

    Pascal M
    http://Tajuddin.whitepagesbd.com

  • How to call a stored procedure stored procedure

    Hello Experts,

    I need help, even if stored procedures. I tried to know without a bit of luck. Is it possible to call the stored procedure to another stored procedure? The problem is my boss want me to work on a stored procedure, but I do not have the appropriate privileges. He won't give me permissions either. He suggested that to a stored procedure and call this stored procedure after creating a new procedure. Is this possible? If Yes, how can I do it?

    I thank in advance

    ascheffer wrote:
    Without the "privileges", whatever it is, your features in other nesting procedures won't help.

    Anton

    Unless...

    It goes to an anonymous PL/SQL block to allow him to test its procedures. ;)

    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    procedure test_proc(p_var IN VARCHAR2) is
      3    begin
      4      dbms_output.put_line(p_var);
      5    end;
      6  begin
      7    test_proc('This is a test proc');
      8* end;
    SQL> /
    This is a test proc
    
    PL/SQL procedure successfully completed.
    
    SQL>
    
  • How to call a stored procedure PL/SQL of the Disqualification?

    I figured I could do this from a Groovy script but I am unable to make it work.

    Let's take the simplest scenario:

    At the end of a job, I have a need to call an once stored procedure that has no arguments.

    Translated by the logic of the stored procedure with Disqualification is not an option.

    If you must call it once at the end of a task, you must use the external task.

    If you call a procedure for each record, it can be done using a script.

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

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

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

    If you need more information, just tell me.

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


    Kind regards.

    Antonio Garcia


    / * callOracleSP * /.

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

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

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


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

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

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

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

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

    strcpy (state_key, 'ca');

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

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

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

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

    return 0;
    }


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

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


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


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



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

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

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

    Hi Antonio,.

    I see this:

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

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

    I do not read correctly?

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

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

    Kind regards

    Mark

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

    Hi all
    I wrote the following stored procedure:

    create or replace
    PROCEDURE SP_GET_NUMBER (p_cursor sys_refcursor, departmentId in number, userId in number, documentTypeId number)
    as
    Enter the integer;
    sqlScript varchar2 (60);
    Start
    sqlScript: = "select registrationnumber_seq.nextval from dual;
    immediately run sqlScript in register;
    dbms_output.put_line ('Nextval is: ' |) To_char (Regid));
    insert into roketsanuser.registrationnumbers
    (id, departmentid, documenttypeid, number, registrationstatus, status, updatedate, updateuserid, version)
    values
    (enter it, null, null, enter it, 0, 0, sysdate, 0, 0);
    commit;
    Open the p_cursor for
    Select id
    roketsanuser.registrationnumbers® systems
    where reg.id = regid;
    end;

    And I define in the annotations in my entity class:

    @Entity (name = "Number")
    @Table (name = "REGISTRATIONNUMBERS")
    @SequenceGenerator (name = "REGISTRATIONNUMBER_SEQ", sequenceName = "REGISTRATIONNUMBER_SEQ")
    @org.hibernate.annotations.NamedNativeQuery (name = "SP_GET_NUMBER", query = "{call? "{= SP_GET_NUMBER (: departmentId,: userId,: documentTypeId)}"
    Callable = true, readOnly = true, resultClass = RegistrationNumber.class)
    @EntityListeners ({BaseEntityListener.class})
    Number/public class extends BaseEntity

    I call the query in my Dao class:

    public number getNumberForIncomingPaperworkByStoredProcedure (EntityManager Manager, number number)
    {
    A session = (Session) manager.getDelegate ();
    query org.hibernate.impl.SQLQueryImpl = (SQLQueryImpl) session.getNamedQuery ("SP_GET_NUMBER");

    query.setParameter ("departmentId", ObjectUtil.isNotNull (registrationNumber.getDepartment ())? registrationNumber.getDepartment () .getId (): "");
    query.setParameter ("userId", ObjectUtil.isNotNull (registrationNumber.getUser ())? registrationNumber.getUser () .getId (): "");
    query.setParameter ("documentTypeId", ObjectUtil.isNotNull (registrationNumber.getDocumentType ())? registrationNumber.getDocumentType () .getId (): "");
    Collection list = query.list ();
    return new RegistrationNumber();
    }

    But when I run the application exception occurred:
    < 01/02/2013 10:04:24 EET > < opinion > < Stdout > < BEA-000000 > < hibernation:
    / * name of SP_GET_NUMBER native SQL query * / {call? = SP_GET_NUMBER (?,?,?)} >
    < 01/02/2013 10:04:27 EET > < opinion > < Stdout > < BEA-000000 > < 10:04:27, 811 ERROR [IncomingPaperworkMBean] EJB Exception:; nested exception is:
    org.hibernate.exception.SQLGrammarException: could not execute the query. nested exception is: org.hibernate.exception.SQLGrammarException: could not execute the query >

    This is perhaps the reason why, please help me?

    Thanks in advance

    Message to research in syntax of:

    @org.hibernate.annotations.NamedNativeQuery

    It seems that following is a possible cause (but I'm not sure about this one):

    Query = "{call?" "{= SP_GET_NUMBER (: departmentId,: userId,: documentTypeId)} '.

    You can change this:

    Query = "(?)". (= appeler SP_GET_NUMBER (: departmentId,: userId,: documentTypeId)) "...

    or

    Query = "(call SP_GET_NUMBER (: departmentId,: userId,: documentTypeId)).

    and check if that helps...

    You can take a look at:

    https://Forum.Hibernate.org/viewtopic.php?p=2401604

    HTH,

    Bravo!
    AJ

  • How to call a stored procedure accepts VARIABLE in run

    Hello

    CREATE OR REPLACE PROCEDURE getEmpName
    * (EMP_UNAME IN VARCHAR, EMP_PWD VARCHAR OUT) *.
    IS
    BEGIN
    SELECT PASS IN EMP_PWD
    USERS
    WHERE NAME = EMP_UNAME;
    END;

    How call this stored using the execute procedure, I tried to run getEmpName('Sai'); and I myself
    ERROR on line 1:
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in the call to 'GETEMPNAME '.
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored

    The Sybrand & Tyro two examples show the declaration of the variable, i.e.

    SQL> variable ename varchar2(100);
    

    You must do it before SQL * Plus could know how to solve: ename in your call.

    Justin

  • call a stored procedure for each row in the transitional attribute and display the data in the form of af: table. The other rows are based on the entities

    Hi Experts,

    JDeveloper 12.1.3.0.0

    I have a VO based on entity object. With a column of the VO is transient attribute (I created).

    I need to call a stored procedure for each row in the transitional attribute and display the data in the form of af: table. As well as other attributes.

    So can anyone suggest how can I achieve this?

    Thank you

    AR

    I think that you need a stored function (which returns the value) in this case, is not?

    Take a look at:

    https://docs.Oracle.com/CD/B31017_01/Web.1013/b25947/bcadvgen005.htm

    and search for:

    Invoking stored function with only Arguments in

    call your function in the Get attribute and return value accessor...

  • Internal error: catalog view incompatible when calling a stored procedure

    Hello

    I use JDeveloper 11.1.1.4

    When you call a stored procedure from AppModuleImpl, I get this error internal error: inconsistent display catalog

    I'll call the stored procedure of this way

    String lErrCode;

    String lErrMsg;

    Result of an integer;

    ARRAY inputArray = null;

    Table STRUCT that can be passed to a PLSQL PROCEDURE

    inputArray =

    JdbcSqlMapper.preparePlSqlArrayUsingVOAttrbs (conn, recordType,

    view, rm);

    OracleCallableStatement st =

    (OracleCallableStatement) conn.prepareCall ("{?}") = call ("+

    procedureName +.

    "(?,?,?))}");

    st.registerOutParameter (1, Types.INTEGER);

    st.setObject (2, inputArray, OracleTypes.ARRAY);

    st.registerOutParameter (2, OracleTypes.ARRAY,

    recordType.getTableType ());

    st.registerOutParameter (3, Types.VARCHAR);

    st.registerOutParameter (4, Types.VARCHAR);

    St.Execute ();

    I checked the subsidies for this package to all users. All users with grants to this package.

    I don't know where I start to debug this issue.

    Kindly help.

    Thank you and best regards,

    John.

    Have yo uchecked the right of the types of data used (at least the TABLE) to the user (referred to Pokusak blog: JPublisher - incompatible catalog display)?

    Timo

  • How to call the procedure in the process

    Hello

    I have create procedure abc.
    How can I call procedure abc in the process in the processing of the Page.
    I want to call this procedure when I press the "submit" button.

    Thank you

    Hello

    Yes, that is correct

    Kind regards
    Jari

  • The call PLSQL stored procedure from the HTML form Submit button

    Hello

    I'm having a little difficulty with the appellant a stored procedure using a html form button. Here is the code I have right now...
    HTP.PRINT('<form action=ZWGKERCF.P_confdelete>');
    HTP.PRINT('<input type=''submit'' value='' Yes '' onClick=''document.getElementById("mypopup").style.display="none"''>');
    HTP.PRINT('</form></div>');
    Here's the question - I need to find a way to pass variables to this stored procedure, so he knows what data to operate on. This stored procedure removes the data in a specific database record and I have to pass three variables to this procedure to run.

    Allows to call class_number, term, conf will impact these three variables and the data will be deleted and the person will see a confirmation screen once the deletion request completed.

    So ideally I would want: ZWGKERCF. P_confdelete (class_number, term, conf), then the stored procedure would deal with the rest!

    Seems simple enough, but I don't know how to make this happen... My thoughts were:

    Transmit data to this (the three areas that I need) html form in hidden variables. Then somehow pass them using the POST method to the procedure and read using GET?

    Can someone clarify what the best way to do it? I feel that its little something miss me you - but I would really like an idea expertise :-)

    Thank you very much in advance!

    -Jeff

    >
    ...

    I would like to assign a variable, the duration, the conf crn all variables in this procedure and then act on them accordingly.

    But you already have it in a variable. If you want you can assign the value again to another variable.

    example of

    PROCEDURE P_confdelete(CRN NUMBER,TERM NUMBER, CONF VARCHAR2)
       IS
          v_crn number(38);
          v_term number(38);
          v_conf varchar2(1000);
    
      BEGIN
           HTP.PRINT('test1 '||crn||'/'||term||'/'||conf); 
    
          v_crn := crn;
          v_term := term;
          v_conf := conf;
    
          HTP.PRINT('test2 '||v_crn||'/'||v_term||'/'||v_conf); 
    
    END P_confdelete;
    
  • How to call the procedure type table

    Hi I have the below requirement

    Created in the sub table type

    CREATE or REPLACE the TYPE char_type IS the TABLE OF VARCHAR2 (4000);

    create or replace procedure test_proc_type (p_type char_type) is

    Start

    I'm looping 1.p_type.count

    dbms_output.put_line (p_type (i));

    end loop;

    end;

    How to call the procedure with parameter as a type!

    SQL> create or replace type  char_type as table of varchar2(4000)
      2  /
    
    Type created.
    
    SQL> create or replace procedure test_proc_type (p_type char_type)
      2  is
      3  begin
      4    for i in 1..p_type.count loop
      5      dbms_output.put_line (p_type(i) ) ;
      6    end loop;
      7  end;
      8  /
    
    Procedure created.
    
    SQL> set serveroutput on
    SQL>
    SQL> exec test_proc_type(char_type('A','B','C','D','E'))
    A
    B
    C
    D
    E
    
    PL/SQL procedure successfully completed.
    
    SQL>
    
  • question on "How to call a method once when starting the application"

    Hello everyone.

    I'm trying to implement that article "How to call a method once when you start the application" by Frank suggests.
    https://blogs.Oracle.com/jdevotnharvest/entry/how_to_invoke_a_method


    Suppose I want to have a single entry point, so in my login.jpsx I have the below:
    <f:view beforePhase="#{login.onBeforePhase}">
    In the 'onBeforePhase' method, I have to pass the phaseEvent, since the signature is as follows:
    public void onBeforePhase(PhaseEvent phaseEvent)
    But how do I know the phaseEvent during the call to the login.onBeforePhase? How the call should be?

    Thank you very much!


    PS. I use jDev 11.1.2.1.0

    You must not pass something to this method, this method is called before each Phase except view restoration
    Just write logic as Frank suggested to the phase in which you want the code to run. You can get the PhaseId analogues

    PhaseId.RENDER_RESPONSE

    public void onBeforePhase(PhaseEvent phaseEvent) {// from Frank's doc
     //render response is called on an initial page request
      if(phaseEvent.getPhaseId() == PhaseId.RENDER_RESPONSE){
    ... etc
    
  • A wrong number or types of arguments in the call to stored procedure

    Hi all...
    I'm missing something simple here, but I don't see what it is.
    I have looked around and cannot know what the problem is.
    Calling a stored procedure in Oracle 11g of Java 6.

    Here is my code:
       CallableStatement proc = null;                
       proc = conn.prepareCall("{ call storedProc(?, ?, ?, ?, ?) }");
       proc.setString("p_header", "8YR6TG");
       proc.setString("p_optype", "A");
       proc.registerOutParameter("p_headerCursor", OracleTypes.CURSOR);
       proc.registerOutParameter("p_detailCursor", OracleTypes.CURSOR);
       proc.registerOutParameter("p_status", OracleTypes.VARCHAR);
       proc.execute();
    Here are my stored procedure:
    PROCEDURE storedProc (
    p_header IN VARCHAR2,
    p_optype IN VARCHAR2,
    p_headerCursor OUT R_CURSOR,
    p_detailCursor OUT R_CURSOR,
    p_status OUT VARCHAR)
    Here's the exception I get:
    java.sql.SQLException: ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'storedProc'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272)
         at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:626)
         at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:181)
         at oracle.jdbc.driver.T4CCallableStatement.execute_for_rows(T4CCallableStatement.java:870)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1081)
         at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2905)
         at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:2996)
         at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4120)
    Can you see what I'm doing wrong here?
    Thanks in advance for your comments!

    Published by: Brady on February 16, 2012 13:02

    try to use digital indexes instead of parameter names.

Maybe you are looking for

  • two new machines synchronize

    Hi 1632 GMT/UTC on Friday, March 15, 2013 I have 2 new machines. When I go through the process of synchronization and try the two options to create an account or I have an account my e-mail address is already in use (maybe off a previous machine.) Ho

  • Firefox cannot connect

    Suddenly, Firefox will connect any more. Done IE. The fact of Thunderbird. The last thing I remember is that I went to one of my regular sites (a local news station) and a message came saying that want to load something. I refused.This is an error me

  • EPrint &amp; LaserJet Pro 276nw

    I installed the printer on my wireless network. The activation process of web Service directly into the printer don't DO NOT WORK. But, I installed the software in my notebook from ASUS EEE, with usb connection to confirm the parameters of the printe

  • mouse doesn't do not rattling

    I just installed Mozilla Firefox browser and it works fine, but I don't have a click now when I use the mouse.  Can someone explain how to restore the rattling? Thank you

  • I have 2 1 GB ram sticks in my computer and it recognizes only 512 MB on each stick.

    HP compaq dc7100cmt Data sheet: System *. System manufacturer: Hewlett-PackardModel: HP Compaq dc7100 CMT (PC936A)The system version:IdentifyingNumber: MXL4400F7VSystem type: X 86-based PC Motherboard *. Mother Board manufacturer: Hewlett-PackardMoth