Incorrect Update Count by executing a stored procedure from Java

Hi Guys,
I am calling a stored procedure from the java program which is modifying the rows of a table. Now I want to know how many rows have been modified by executing the stored procedure. I am writing the following code for the purpose:
OracleCallableStatement stmt =
(oracle.jdbc.driver.OracleCallableStatement)con.prepareCall("{callsp_um_setForumID(?,?)}");
stmt.setInt(1,101);
stmt.setInt(2,666);
n = stmt.executeUpdate();
System.out.println(n + " row(s) updated");
This procedure is actually modifying the table(When I query the databse it has modified 1 row). But it is returning a value 0 and is printing "0 row(s) updated".
Is there a way by which I can find out the number of rows updated by executing the stored procedure?
Thanks
Sachin
[email protected]

I'm no expert on this, but I have a similar call where I fetch
an Oracle REF CURSOR from a call to a stored function. If you
fetch the cursor as an Object from your CallableStatement, you
can then cast it to a ResultSet e.g.
mystatement.executeUpdate();
ResultSet rs = (ResultSet) mystatement.getObject(1);
Then you should be able to loop through your ResultSet as usual.
Good luck!
Chris

Similar Messages

  • Error while executing a stored procedure from forms6i

    When I execute a STORED PROCEDURE from ORACLE DB 10g this procedure works perfectly fine.
    But when I execute the same from the FORMs 6i I get the following error:
    PDE-PLU022 Don't have access to the stored program unit
    XMLPARSERCOVER in schema CARE.
    where XMLPARSERCOVER is the class and
    CARE is the schema.
    Regards,
    Jignesh S

    I have tried this with both the owner of the schema and the intended user, -from both forms and directly.
    All rights was granted on the stored procedure. Since posting I have found that one of the tables that the procedure might insert into, was not explicitly granted to the intended user, and after rectifying that the error message went away.
    -however, the procedure now silently "finishes" without any evidence that it ever ran, if invoked from the forms application. When invoked from SQL Plus (or JDev, or Toad) it runs as expected.
    I have no public synonym for the procedure, -is that necessary?
    The stored procedure in question is implemented in java, and published as a stored procedure. It does rather heavy lifting, when running, using a view against another server , updating local tables and quite a lot of data validation/cleansing, and logging. All recourses are within the same schema.
    Any ideas?

  • Error ORA-04031 while executing a stored procedure from Pro C++ code

    I am getting the error ORA-04031(Unable to allocate 4096 bytes of shared memory("Shared Pool",.....)) while trying to execute a stored procedure from my pro*C application. This happens only after a few hours since the application has been running. I am closing the cursor after every database call.
    Does anyone know why it is happening and any possible solutions?
    TIA
    Srithaj.

    One thing that can be done is to flush the shared pool before starting the application.
    alter system flush shared pool;
    Another is to increase the shared pool size by setting the parameter shared_pool_size in init_sid.ora file.
    null

  • Execute a stored procedure from a JSP.(Help...)

    How can I execute a stored procedure from a JSP.
    Wich tags I need to use ???
    I'm using the oracle thin JDBC.
    please help me.
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Mario Bellido ([email protected]):
    How can I execute a stored procedure from a JSP.
    Wich tags I need to use ???
    I'm using the oracle thin JDBC.
    please help me.<HR></BLOCKQUOTE>
    I just try a simple call with a data tag just like this (see category.jsp in the onlineorder example provided with Jdev 3.2.3):
    <!-- Tutorial - ApplicationModule Tag -->
    <%@ taglib uri="/webapp/DataTags.tld" prefix="jbo" %>
    <jbo:ApplicationModule configname="OnlineOrders.OnlineOrdersModule.LocalConfig" id="OnlineOrdersModule" username="BC4J" password="BC4J" />
    <!-- Tutorial - DataSource Tag -->
    <jbo:DataSource id="category" appid="OnlineOrdersModule" viewobject="CategoryView" ></jbo:DataSource>
    <jbo:ExecuteSQL appid="OnlineOrdersModule" >
    insert into tablejsp values ('testtable')
    </jbo:ExecuteSQL>
    <jbo:ExecuteSQL appid="OnlineOrdersModule" >
    call testjsp()
    </jbo:ExecuteSQL>
    <jbo:Commit appid="OnlineOrdersModule" />
    testjsp is a stored PL/SQL procedure without arguments.
    null

  • Calling stored procedure from Java raises ORA-1722 exception

    Hi,
    As the title says, when I call the stored procedure from java I got the exception ORA-1722 (invalid number) but I've checked and rechecked my procedure on SQL-Developer and It's alright it works nice and clean !
    What's happening? is there something I'm missing?
    The way I call the stored procedure is:
        public void execProcedure(String procedure) {
            CallableStatement cs;
            try {
                cs = conn.prepareCall(procedure);
                cs.execute();
            } catch (SQLException ex) {
                Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
         where
        String procedure = "{call validateinfo}"I really need help on this, it's frustraiting me 'cause I need to finish a system but this little big problem is killing me ...
    Thanks any advice is very welcome :)

    Thanks for your help. Haven't tested the SP with a DB access client... which one do you recommend to use?
    The SP is the following:
    create or replace
    PROCEDURE validateInfo IS
      var number;
    BEGIN
      UPDATE temp_desarrollo
      SET status = '1';
      COMMIT;
      // Some string validations ...
      //This one just checks if the value of "monto" is a number
      //This update goes good
      UPDATE temp_desarrollo tmp
      SET cve_status = Decode(cve_status, NULL, '15', cve_status||',15')
      WHERE IsNumber(tmp.monto) = 'F';
      COMMIT;*/
      //This one just checks if the value of "monto" is greater than 0
      //if not, change de add to cve_status an errorValue
      UPDATE temp_desarrollo tmp
      SET cve_status = Decode(cve_status, NULL, '14', cve_status||',14')
      WHERE (cve_status NOT LIKE '%15%' OR cve_status IS NULL)
      AND to_number(tmp.monto) <= 0;
      COMMIT;
      //More string validations
      EXCEPTION
        WHEN OTHERS THEN
          var := SQLCODE;
          insert into excepciones values(to_char(var));
    END;I've deleted much code from the SP since I know there's nothing to do with the excepcion, just that UPDATE statement is the one giving me the exception.
    If those two UPDATES statements work with the same field (monto) why the first one is succeding and the second one not?
    Cheers,
    Federico
    P.S. the "isNumber" function is as follows, just in case.
    create or replace
    function IsNumber(val1 varchar2) return varchar2 is
      n number := null;
    begin
      n := to_number(val1,'9999999999999999.99');
        return 'T';
      exception
        when others then
          return 'F';
    end;

  • Error while calling stored procedure from Java

    Hi Guys,
    How are you everybody? I hope everything is goin fine on your side. I have one issue in PL/SQL while calling below stored procedures from Java.
    Problem Description: We have a stored procedure PROCEDURE BULK_INSERTS (
    V_SESSION_ID_TAB IN T_SESSION_ID_TAB_TYPE,
    V_SERVICE_TYPE_TAB IN T_SERVICE_TYPE_TAB_TYPE,
    V_SERVICE_LOCATION_TAB IN T_SERVICE_LOCATION_TAB_TYPE,
    V_SERVICE_CALL_NAME_TAB IN T_SERVICE_CALL_NAME_TAB_TYPE,
    V_SERVICE_CALL_START_TIME_TAB IN T_SERVICE_CALL_ST_TAB_TYPE,
    V_SERVICE_CALL_END_TIME_TAB IN T_SERVICE_CALL_ET_TAB_TYPE,
    V_SERVICE_CALL_DURATION_TAB IN T_SERVICE_CALL_DUR_TAB_TYPE,
    V_STATUS_TAB IN T_STATUS_TAB_TYPE,
    V_NOTES_TAB IN T_NOTES_TAB_TYPE
    ) and we are getting ora errors while calling this stored procedure from java.
    All tab types are declared locally, at package level.
    Here is error which occur while calling this sp:
    {call BULK_PKG.BULK_INSERTS(?,?,?,?,?,?,?,?,?)}
    And the parameter types we are using are:
    SESSION_ID - NUM_TAB_TYPE
    SERVICE_TYPE - VAR_TAB_TYPE
    SERVICE_LOCATION - VAR_TAB_TYPE
    SERVICE_CALL_NAME - VAR_TAB_TYPE
    SERVICE_CALL_START_TIME - DATE_TIME_TAB_TYPE
    SERVICE_CALL_END_TIME - DATE_TIME_TAB_TYPE
    SERVICE_CALL_DURATION - NUM_TAB_TYPE
    STATUS - VAR_TAB_TYPE
    NOTES - VAR_TAB_TYPE
    And the Exception stack trace is:
    ERROR (com.att.retail.r2d2.persistence.dao.ExternalServiceCallDAO.saveExternalServiceCallInfo(ExternalServi
    ceCallDAO.java:143)@ExecuteThread: '252' for queue: 'weblogic.kernel.Default') {Error attempting to save collected ESC data}
    java.sql.SQLException: ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'BULK_INSERTS'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
    at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1030)
    at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:191)
    at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:944)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1222)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3381)
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3482)
    at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:3856)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1373)
    at weblogic.jdbc.wrapper.PreparedStatement.execute(PreparedStatement.java:98)
    at com.att.retail.r2d2.persistence.dao.ExternalServiceCallDAO.doBulkInsert(ExternalServiceCallDAO.java:220)
    at com.att.retail.r2d2.persistence.dao.ExternalServiceCallDAO.saveExternalServiceCallInfo(ExternalServiceCallDAO.java:138)
    Please help my guys out of this. I will really appreciate all suggestions and advices.
    Thank you everybody.

    I am trying to pass parameter to test my procedure but it is giving this error : ORA-06531: Reference to uninitialized collection
    ORA-06512: at line 12
    Here is example for my test procedure:
    declare
    v_session_id_tab SESSION_ID_TAB_TYPE;
    v_service_type_tab SERVICE_TYPE_TAB_TYPE ;
    v_service_location_tab SERVICE_LOCATION_TAB_TYPE ;
    v_service_call_name_tab SERVICE_CALL_NAME_TAB_TYPE;
    v_service_call_start_time_tab SERVICE_CALL_ST_TAB_TYPE;
    v_service_call_end_time_tab SERVICE_CALL_ET_TAB_TYPE;
    v_service_call_duration_tab SERVICE_CALL_DUR_TAB_TYPE;
    v_status_tab STATUS_TAB_TYPE;
    v_notes_tab NOTES_TAB_TYPE;
    begin
    v_session_id_tab(1) := 1;
    v_service_type_tab(1) := 'db';
    v_service_location_tab(1) := 'local';
    v_service_call_name_tab(1) := 'Name of call';
    v_service_call_start_time_tab(1) := SYSDATE;
    v_service_call_end_time_tab(1) := SYSDATE;
    v_service_call_duration_tab(1) := 100;
    v_status_tab(1) := 'Z';
    v_notes_tab(1) := 'NOTES';
    BULK_INSERTS (v_session_id_tab,v_service_type_tab, v_service_location_tab,v_service_call_name_tab,v_service_call_start_time_tab,v_service_call_end_time_tab,
    v_service_call_duration_tab, v_status_tab, v_notes_tab);
    end;
    I declare all types at schema level.
    Please give your comments.
    Thank you

  • Problem in calling Oracle stored procedure from Java.

    I am trying to invoke the Oracle stored procedure from Java. The procedure does not take any parameters and does not return anything. If I call it from SQL prompt it is working perfectly. I am calling it in my program as follows.
    callable_stmt=con.prepareCall("{call pkg_name.proc_name()}");
    callable_stmt.execute();
    The problem is the control-of-flow is getting strucked in the second line I wrote. It is not giving any error also.
    Please clarify me what's wrong with my code?
    Seenu.

    And how long does the stored procedure take to run from your client machine when running it via sqlplus?

  • Calling Stored Procedures from JAVA Application

    Hi all,
    i am using JDeveloper 3.2.2 for creating a DB Application that
    uses Oracle8i as DB Server.
    One approach of the application is to only use PL/SQL Stored
    Procedures to write Data back to the DB.
    Some of the stored procedures expect more than 20 parameters.
    I want to know if there is a better way to call such a stored
    procedure from Java than using a CallableStatement and setting
    its 20 parameters.
    Another reason why the way above isnt possible for me is that
    i need a dynamic way to set the parameters of the stored
    procedure.
    A solution for that dynamic way i could think of is to get
    the information of the stored procedure by using some functions
    of DatabaseMetaData and than use this information to map the
    parameters with their respective variables in the java
    application.
    The best argument against this way is that it would be time and
    performance consuming.
    So could anybody tell me a solution to call PL/SQL stored
    procedures from java which is better than doing something like:
    String calString = "{Call myStoredProc(";
    while(counter < 22) {
    params += "?";
    if(counter<21) params += ",";
    counter++;
    calString += params + ")}";
    try {
    CallableStatement cs = session.prepareCall(calString);
    } catch(SQLException ex) { ... }
    cs.setString(1, var1);
    cs.setString(1, var2);
    And that for every Stored Procedure i want to call ?!?
    Any help or direction-leading would be really appreciated.
    Tank you much.
    MfG,
    Oliver Bankel

    Hi Oliver,
    If you your Stored Procedures were in Java and seamlessly
    integrated with your Java application would that make your life
    easier?
    I don't know if this is a practical or acceptable solution in
    your environment but it would certainly solve all of your issues
    and provide your with a couple of nice advantages. Scalability
    and platform independence are just a couple I could think of.
    There is a tool called in2j (see http://www.in2j.com) which will
    automatically migrate your PL/SQL Stored Procedures into Java.
    You can download a copy of the tool and migrate your PL/SQL to
    Java with no upfront costs. If you're happy with the generated
    Java and want to deploy it, the migration fee falls due - simple.
    Hope this helps.
    Elton

  • DB2 Stored Procedure from Java-JDBC

    Hi All,
    I am using DB2 stored procedure which have been written in COBOL. I have two types of stored procedures. First types of stored procedure takes IN parameter and returns OUT parameter. These stored procedures are working fine. The second type of stored procedure takes IN parameter and returns a CURSOR. According to Database team (who wrote these stored procedure) claims that they can see data in a cursor when they test these stored procedure directly in the database. However, when I run these stored procedures from Java code it returns NULL ResultSet. Here is the code:
    public SearchResult getAllBenefitHEDType(SearchParameter searchParam) throws DAOException {
    log.debug(" getAllBenefitHEDType method - entering ");
    HashMap searchParametersMap = searchParam.getHashMap();
    SearchResult searchResult = new SearchResult();
    String type = (String) searchParametersMap.get(UDFConstant.LOOKUP_SEARCH_TYPE);
    HashMap resultParametersMap = new HashMap();
    ArrayList resultSetDTO = new ArrayList();
    try {
    conn = this.getConnection();
    conn.setAutoCommit(false);
    System.out.println("getAllBenefitHEDType Step 1");
    CallableStatement cs = conn.prepareCall("{call TEST.APS003(?)}"); // Stored Procedure with one IN parameter.
    cs.setString(1,type);
    boolean retVal = cs.execute(); // this should return true if ResultSet is available.. in my case it is returning false.
    // I tried with getting the Object
    ResultSet rs = (ResultSet) cs.getObject(1); // this should give me a valid result set ... in my case I am getting null
    if (rs!=null) {
    System.out.println("getAllBenefitHEDType Step 4A Result Set Not Null");
    } else {
    System.out.println("getAllBenefitHEDType Step 4A Result Set Is Null");
    // I tried getting the resultset
    ResultSet rs1 = cs.getResultSet(); // this should give me a valid result set ... in my case I am getting null
    if (rs1!=null) {
    System.out.println("getAllBenefitHEDType Step 4D Result Set Not Null");
    } else {
    System.out.println("getAllBenefitHEDType Step 4D Result Set Is Null");
    while (rs.next()) {
    System.out.println("getAllBenefitHEDType Step 5");
    LookupDTO lookupDTO = new LookupDTO();
    // the following code populate the Lookup DTOs from ResultSet.

    A few comments...
    1) Creating tables, particularly tables whose names seem to imply that they are temporary tables, on the fly in a stored procedure is a bad idea. That is not the way to work with Oracle, though it is a common practice in other databases like SQL Server. There is undoubtedly a better way to do this in Oracle if you can explain what you're trying to accomplish from a business standpoint.
    2) If you are going to use dynamic SQL, you almost always want to use bind variables, not literals. One of the quickest ways to kill an Oracle database's performance is to not use bind variables.
    3) As has already been mentioned, assuming FH_INICIO is a DATE column, you need to put an explicit TO_DATE around your strings in order to convert them to dates. Otherwise, Oracle's implicit cast depends on the session's NLS_DATE_FORMAT, which is likely to be different in different client applications and from different client machines.
    Justin

  • How to send a Varying Array param to a PL/SQL Stored Procedure from Java

    * I am VERY new to jdbc, and even somewhat new to Java
    * I'm using Java 1.5, Oracle 10g.
    * I need to call the following PL/SQL Stored Procedure from Java:
    procedure setEventStatus
    i_deQueueStatus in deQueueStatus_type
    *deQueueStatus_type is the following (an array of deQueueStatus_OBJ):
    CREATE OR REPLACE TYPE deQueueStatus_OBJ as object
    eventID number (20),
    dequeuestatus varchar2(20)
    CREATE OR REPLACE TYPE deQueueStatus_TYPE IS VARYING ARRAY(500) of deQueueStatus_obj
    *I have created a Java object as follows:
    public class EventQueueDeQueueStatus
         long      eventID;
         String      dequeueStatus;
         EventQueueDeQueueStatus(long eventID, String dequeueStatus)
              this.eventID = eventID;
              this.dequeueStatus = dequeueStatus;
    I have an ArrayList of these.
    I need to pass this list to the Stored Procedure. How do I create a java.sql.Array so I can call CallableStatement.setArray to set the parameter? Or do I use something else? I have tried setObject with both the ArrayList and also with a primitive array, but got "Invalid Column Type" both times.
    Any help would be greatly appreciated. I just got this task today, and I have to make it work by Tuesday :-( !
    Thanks,
    Kathy

    Kathy,
    Search the archives of this forum and the JDBC forum for the terms STRUCT and ARRAY and you can find some sample code on the JDBC How-To Documents page and the JDBC Samples which can both be accessed from this page:
    http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html
    Good Luck,
    Avi.

  • Calling packaged stored procedure from Java

    Hi All,
    I'm trying to call a stored procedure from Java but I'm having
    problems with registrating the output parameter. I'm getting
    the error: Conflicting parameters.: sqltype=2003
    This is the stored procedure which is located in a package in
    the Oracle database:
    package Pack_GetAgencyInformation as
    Type InfoType is record ( agen_code varchar(3), agen_designation
    varchar(30), agen_adresse varchar(60), agen_tel varchar(12) );
    function GetAgencyInformation( P_AGENCE VARCHAR )
    return Pack_GetAgencyInformation.InfoType
    end Pack_GetAgencyInformation;
    This is the Java source from where I'm calling the procedure:
    //DriverManager.registerDriver (new
    oracle.jdbc.driver.OracleDriver());
         Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@164.48.69.125:1521:ventes", "system", "*****
    // @machineName:port:SID,
    userid, password
    CallableStatement cs = conn.prepareCall("{ ? = call
    Pack_GetAgencyInformation.GetAgencyInformation( ? )}");
         try {
              cs.registerOutParameter( 1,
    oracle.jdbc.driver.OracleTypes.ARRAY);
         } catch (SQLException e) {
              e.printStackTrace();
         cs.setString(2, "001" );
         //ResultSet rset = cs.executeQuery();
    The stacktrace:
    java.sql.SQLException: Parametertypen conflicteren.:
    sqlType=2003
    at oracle.jdbc.dbaccess.DBError.throwSqlException
    (DBError.java:168)
    at oracle.jdbc.dbaccess.DBError.throwSqlException
    (DBError.java:210)
    at
    oracle.jdbc.driver.OracleCallableStatement.registerOutParameter
    (OracleCallableStatement.java:220)
    at
    oracle.jdbc.driver.OracleCallableStatement.registerOutParameter
    (OracleCallableStatement.java:350)
    at dbAccess.main(dbAccess.java:25)
    I think it has to do with the type InfoType which is created in
    the Stored Procedure. I'm absolute no Oracle expert and I
    prefer not to make changes to the Oracle database. So any
    solution in Java is welcome!
    BR, H.Rietman

    I managed to get it to work only by changing the stored
    procedure. I have changed the return type record to a Ref
    Cursor type (had to change alot of code for this). It seams
    that Oracle JDBC drivers DON'T support the Record type as a
    return type.
    So the next question is: is it possible to typecast a record
    type to a ref cursor type in Oracle. In this way I can easily
    change the return type for the stored procedures.
    /Harald

  • Need coding support for Accessing MYSQL stored procedure from java

    Hi every one,
    I need coding support for accessing Mysql stored procedure from java and JSP.
    Please help me
    pranav

    You'd better have a recent version of MySQL, because earlier ones didn't support stored procs.
    If your MySQL and driver support stored procs, maybe you just need a JDBC stored proc tutorial.
    %

  • Executing a stored procedure from an Ifs Program

    I have a need to execute a stored procedure in another schema
    within the same database, and I need to receive an OUT parameter
    to continue processing. The oracle.ifs.server.sql.IfsConnection
    is not in my class path. Can someone tell me which jar file to
    adde to my classpath to have this funcitonality that IFS claim.
    Regards,
    Jeff

    Guys I need help with this one as soon as possible.

  • Execute oracle stored procedure from C# always returns null

    Hi,
    I'm trying to execute a stored procedure on oracle 9i. I'm using .Net OracleClient provider.
    Apparently, I can execute the stored procedure, but it always returns null as a result (actually all the sp's I have there returns null)! I can execute any text statement against the database successfully, and also I can execute the stored procedure using Toad.
    This is not the first time for me to call an oracle stored procedure, but this really is giving me a hard time! Can anyone help please?
    Below are the SP, and the code used from .Net to call it, if that can help.
    Oracle SP:
    CREATE OR REPLACE PROCEDURE APIECARE.CHECK_EXISTENCE(l_number IN NUMBER) AS
    v_status VARCHAR2(5) := NULL;
    BEGIN
    BEGIN
    SELECT CHECK_NO_EXISTENCE(to_char(l_number))
    INTO v_status
    FROM DUAL;
    EXCEPTION WHEN OTHERS THEN
    v_status := NULL;
    END;
    DBMS_OUTPUT.PUT_LINE(v_status);
    END CHECK_CONTRNO_EXISTENCE;
    C# Code:
    string connStr = "Data Source=datasource;Persist Security Info=True;User ID=user;Password=pass;Unicode=True";
    OracleConnection conn = new OracleConnection(connStr);
    OracleParameter param1 = new OracleParameter();
    param1.ParameterName = "v_status";
    param1.OracleType = OracleType.VarChar;
    param1.Size = 5;
    param1.Direction = ParameterDirection.Input;
    OracleParameter param2 = new OracleParameter();
    param2.ParameterName = "l_number";
    param2.OracleType = OracleType.Number;
    param2.Direction = ParameterDirection.Input;
    param2.Value = 006550249;
    OracleParameter[] oraParams = new OracleParameter[] { param1, param2 };
    OracleCommand cmd = new OracleCommand("CHECK_EXISTENCE", conn);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddRange(oraParams);
    conn.Open();
    object result = cmd.ExecuteScalar();
    conn.Close();

    Hi,
    Does that actually execute? You're passing two parameters to a procedure that only takews 1 and get no error?
    Your stored procedure doesnt return anything and has no output parameters, what are you expecting to be returned exactly?
    If you're trying to access V_STATUS you'll need to declare that as either an output parameter of the procedure, or return value of the function, and also access it via accessing Param.Value, not as the result of ExecuteScalar.
    See if this helps.
    Cheers,
    Greg
    create or replace function myfunc(myinvar in varchar2, myoutvar out varchar2) return varchar2
    is
    retval varchar2(50);
    begin
    myoutvar := myinvar;
    retval := 'the return value';
    return retval;
    end;
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    public class odpfuncparams
         public static void Main()
          OracleConnection con = new OracleConnection("user id=scott;password=tiger;data source=orcl");
          con.Open();
          OracleCommand cmd = new OracleCommand("myfunc", con);
          cmd.CommandType = CommandType.StoredProcedure;
          OracleParameter retval = new OracleParameter("retval",OracleDbType.Varchar2,50);
          retval.Direction = ParameterDirection.ReturnValue;
          cmd.Parameters.Add(retval);
          OracleParameter inval = new OracleParameter("inval",OracleDbType.Varchar2);
          inval.Direction = ParameterDirection.Input; 
          inval.Value="hello world";
          cmd.Parameters.Add(inval);
          OracleParameter outval = new OracleParameter("outval",OracleDbType.Varchar2,50);
          outval.Direction = ParameterDirection.Output;
          cmd.Parameters.Add(outval);
          cmd.ExecuteNonQuery();
          Console.WriteLine("return value is {0}, out value is {1}",retval.Value,outval.Value);
          con.Close();
    }

  • Execute Oracle Stored Procedure from Excel

    Is it possible to execute an Oracle Stored Procedure from Microsoft Excel and return the result of the Oracle Store Procedure into the excel spreadsheet.

    Yes. You can use Oracle Objects for OLE to accomplish this. It comes with Excel examples and an online help file with many more examples.

Maybe you are looking for