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();
}

Similar Messages

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

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

  • How to execute oracle stored procedure through php as externally?

    hi...
    i am searching for the way that how to execute oracle stored procedure through web service, i am using php and mysql, i have some stored procedures in oracale database, i want to execute them, from php, means the database will be remain mysql, and the stored procedures of oracle will be executed externally...
    Kind regards,
    Wilayat.

    Ok, so first of all this is a kind of strange question. Since Oracle and MYSQL can happily live side by side.
    Make sure you have the oracle client (instant or regular ) installed and OCI_8 is set up and working correctly in PHP. If it is, when you run the phpinfo() routine you will see oci_8 on there. IF PHP connects just fine from the command line yet apache wont connect check permissions and things like the LD_Library Path.
    Then in php, right along with your MySQL statements run Oracle Statements eg:
    <?php
    $OraDB = oci_connect(name,pass,tnsname);
    $MySQLdb = mysql_connect([parms]);
    $oraQueryText = "begin sp_some_proc([some parms]); end;" ;
    $mysqlQuery = " Some mysql Query";
    $oraQuery = oci_parse($OraDB,$oraQueryText );
    oci_execute($oraQuery);
    mysql_execute([parms]);
    ?>
    Use the standard fetch code to get data from either of them.
    If you cannot and I mean absolutely cannot get an admin to link in OCI_8 then you still have recourse although it will be tedious as hell. PHP allows you to exec calls to the OS. You still MUST make sure the Oracle Client is installed and that sqlplus runs from the command line. You will more then likely have to have a shell script written to do this as well, but maybe not as I have never tried it with the exception of capturing the return value of sqlplus and you will have to dig into sqlplus to get it to send its results to a file you can then parse with php.
    Good Luck!

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

  • Invoking Oracle stored procedures from within a JDBC channel for PI 7.1

    Hi ,
    Can anybody tell me that is it possible to invoke Oracle stored Procedure from within a JDBC  sender channel for PI 7.1.
    Its working in XI3.0 and XI 7.0 for Oracle DBMS versions >= 10.2.x. But I am not sure,whether it will work for PI 7.1 also.
    Thanks & Regards,
    Saru

    HI,
    refer below link,there is no much difference in PI7.1 ,executing stored procedure is same .
    http://help.sap.com/saphelp_nwpi71/helpdata/EN/44/7b72b2fde93673e10000000a114a6b/content.htm
    Regards,
    Raj

  • Calling Oracle stored procedure from xMII Query Templates.

    Hi All,
    We have a requirement to call a Oracle stored procedure from xMII, the SP expects some inputs and then it returns multiple rows.
    I tried different approches with no results, I remember some posts on the same topic but I could not get in search results.
    Looking for some help in this regards
    Rupesh.

    Hi Rupesh Bajaj,
    In oracle stored procedure we have to use Packages..if you used packages the u have to assign to some variable.
    To calling Stored procedure  in Query Template is CALL Testing('[Param.1]','[Param.2]',,:X)
    In above line Testing is Stored procedure name and Param.1 is parameters and X is Package.
    Thanks
    Ravilla Ramesh

  • 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

  • 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

  • Executing a stored procedure from a java program

    Hi.. how can i call a oracle stored procedure from a java
    program. the OSP has four IN parameters and one OUT parameter(a
    cursor). when i try this way.. i get an error
    con = DriverManager.getConnection(url, "stored", "stored");
    CallableStatement cs =
    con.prepareCall(
    "{call stored_proce_1(?,?,?,?,?)}");
    cs.registerOutParameter(1, OracleTypes.CURSOR);
    cs.setString(2, "14541");
    cs.setString(3, "gen");
    cs.setInt(4, 0);
    cs.setInt(5, 5);
    ResultSet rs =cs.getResultSet();
    while(rs.next()){
    System.out.println(rs);
    appreciate ur help.
    qs

    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

  • Can sqltaglib.tld execute Oracle stored procedure?

    Is it possible to execute Oracle stored procedure through Oralce's own sqltaglib.tld. The sqltaglib on-line manual only shows how to run SQL query/insert/update statement.
    Thanks,

    I went to a few forums and asked the same question. The boys down at Oracle Community Forums shed some light on this subject and, with their help, I was able to figure it out. Here is the thread for those who want to read: [My Thread @ Oracle Community Forums|http://forums.oracle.com/forums/thread.jspa?messageID=2721348?].
    THE SOLUTION
    cs = con.prepareCall("{ call get_countries(?) }");
    cs.registerOutParameter(1, OracleTypes.CURSOR);
    cs.execute();
    ResultSet rs = ((OracleCallableStatement) cs).getCursor(1);

  • Executing an Oracle Stored Procedure from Sender JDBC adapter

    I could really use some help from someone who had done this before. 
    I've read the help about using the JDBC sender adapter, but it's not helping enough.
    I found this line: "Specify an SQL EXECUTE statement to execute a stored procedure, which contains exactly one SELECT statement.
    The expression must correspond to the SQL variant supported by the relevant JDBC driver. It can also contain table JOINs."
    That's definately what we want to do, but we can't figure out the syntax.
    The procedure in oracle looks like this:
    CREATE OR REPLACE PROCEDURE test_ref_cursor
    ( cur_generic IN OUT result_sets.cur_generic)
    as
    BEGIN
    Open cur_generic for
    select
       proposal_number,
       to_char(sequence_number),
       column_name,
       column_value,
       update_timestamp,
       update_user
       from
       coeus.sap_test;
    END test_ref_cursor;
    And we have tried every kind of statement we can think of, but the file adapter always gives us an "invalid sql statement" error.
    Does anyone know what syntax we need to put in the "Query SQL Statement" in the JDBC sender adapter in order to call this procedure?  Or is there something wrong with the procedure that is causing the error?
    <i>I will absolutely return and give points, but PLEASE read my whole post before answering and do not just link me to or quote the help for configuring a sender JDBC adapter or blogs that are about the JDBC adapter in general but do not deal with the issues I am having. Thank you.</i>

    Hi Vanda,
    Unfortunately, the sender JDBC adapter does not support Oracle's store procedure/function.  Unlike stored procedures from other database vendors, Oracle returns a cursor, not a resultset.  The sender JDBC adapter must send a resultset to XI.
    There are 2 possible ways you can accomplish this:
    1.  Use BPM and call the Oracle stored procedure using a receiver adapter via a asynch-synch bridge.
    2.  Develop a user-module for the adapter, which can be used with a sender adapter.
    Thanks
    Prasad

  • 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

  • Execute oracle stored procedure in CF8

    I am executing a stored procedure like this.
    <cfstoredproc procedure="GetAction"
    datasource="test_DSN">
    <cfprocparam cfsqltype="CF_SQL_INTEGER"
    dbvarname="actionId" type="in" value="1">
    <cfprocresult name="actions" resultset="1" >
    </cfstoredproc>
    and my stored procedure in oracle is,
    create or replace function GetAction(actionId IN
    ACTION.ID%TYPE)
    RETURN ACTION%ROWTYPE
    IS
    actions
    ACTION%ROWTYPE;
    begin
    select *
    INTO actions
    FROM ACTION WHERE ID = actionId;
    RETURN actions;
    end GetAction;
    then I get the error message like,
    ORA-01008: not all variables bound
    Please help me on this.
    Thanx

    If you want to return a result set (result of a query) from
    your PL/SQL, you will have to do what Daverms suggested and convert
    your function to a procedure
    and use a reference cursor to return your result set. Your
    procedure will have to be contained in a package in order for you
    to declare a ref cursor "globally" so that it can be accessed by
    CF.
    Oh, and be sure to change your cfstoredproc procedure
    parameter to add the package name to the proc name.
    <cfstoredproc procedure="your_pkg.GetAction"
    datasource="test_DSN">
    Phil

  • Calling Oracle stored procedure from java

    The following query calls a stored procedure TRANSLATE_ZONEPATH_ID defined in a package MT by the user MTDBA. currentZone is a member variable of the class, and currently has value 1
    This query works just fine when I run it from SQLPlus* connected as MTDBA.
    But from java, the following piece throws exception saying "invalid column name"
    String query = "SELECT MTDBA.MT.TRANSLATE_ZONEPATH_ID('"+currentZone+"') "
    + "FROM DUAL ";
    try
    Statement stmt = conn.createStatement();
    ResultSet rst = stmt.executeQuery(query);
    if (rst.next())
    fullName = rst.getString(1);
    stmt.close();
    Anyone got any clue ?

    I always use CallableStatement to execute a stored procedure or function in a database (Oracle).
    try this:
    <code>
    CallableStatement cs = dbConnection.prepareCall("{ ? =
    MTDBA.MT.TRANSLATE_ZONEPATH_ID(?)}");
    cs.setString(1, currentZone);
    cs.registerOutParameter(1, Types.VARCHAR);
    cs.executeUpdate();
    fullname = cs.getString(1);
    cs.close();
    </code>
    There is also a jdbc forum, where your should post this kind of problem :-)
    Hope this help's
    ThK

Maybe you are looking for