Question

Can anyone help me solve this issue please. I'm getting this error PLS-00306: wrong number or types of arguments in call to 'INSERTFORUM' ORA-06550: line 1, column 7: PL/SQL: Statement ignored

I checked the first line of my stored procedure and my parameters in C# and I don't see anything missing..course_ID int32, is also in my procedure, s where is the error? Thank you

My Oracle stored procedure

CREATE OR REPLACE PROCEDURE INSERTforum(
       p_course_id IN Int,
       p_question IN Varchar,
       p_postername IN Varchar,
       p_blog_date IN Date)
AS
BEGIN

  INSERT INTO forum ("COURSE_ID", "QUESTION", "POSTERNAME", "BLOG_DATE") 
  VALUES (p_course_id, p_question,p_postername, p_blog_date);

  COMMIT;

END;
/

C# code behind

    OracleCommand oraCmd = new OracleCommand("InsertForum", oraConnection);
oraCmd.CommandType = System.Data.CommandType.StoredProcedure;
                                                                /*or Decimal*/
oraCmd.Parameters.Add(new OracleParameter("p_course_id", OracleDbType.Int32,
                      System.Data.ParameterDirection.Input)).Value = 123;
oraCmd.Parameters.Add(new OracleParameter("p_question",  OracleDbType.Varchar2,
                      System.Data.ParameterDirection.Input)).Value = "question";
oraCmd.Parameters.Add(new OracleParameter("p_postername", OracleDbType.Varchar2,
                      System.Data.ParameterDirection.Input)).Value = "postername";
oraCmd.Parameters.Add(new OracleParameter("p_blog_date", OracleDbType.Date,
                      System.Data.ParameterDirection.Input)).Value = DateTime.Now;
try 
{
    oraCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);

}

Was it helpful?

Solution

You are using Microsoft Oracle Client (using System.Data.OracleClient). Your life would be a bit easier if you used appropriate version of Oracle Data Provider for .NET of Oracle Data Access Components(ODAC) - you can take advantage of native oracle data types and features. Besides, try to use Oracle (Not ANSI data types, which will be converted to Oracle native data types anyway) data types. Use number instead of int for instance. Moreover, use varchar2() data type instead of varchar. Although varchar2 and varchar are synonyms as of now, behavior of varchar may change in the future, so better stick to varchar2.

Here is an example:

Set-up:

/* your table */
create table forum(
  course_id  number,
  question   varchar2(123),
  postername varchar2(123),
  blog_date  date
);

/* the stored procedure*/
create or replace procedure InsertForum(
  p_course_id  in number,
  p_question   in varchar2,
  p_postername in varchar2,
  p_blog_date  in date
) as
begin
  insert into forum (course_id, question, postername, blog_date) 
    values (p_course_id, p_question, p_postername, p_blog_date);
  commit; 
  /* As a side note. It would be better to allow a calling application
     to commit or rollback transaction. 
     */
end;

C# code:

...
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
....

string oraConnectionString = "Data source=data_source;User id=user;password=pwd;";
OracleConnection oraConnection = new OracleConnection(oraConnectionString);
oraConnection.Open();

OracleCommand oraCmd = new OracleCommand("InsertForum", oraConnection);
oraCmd.CommandType = System.Data.CommandType.StoredProcedure;
                                                                /*or Decimal*/
oraCmd.Parameters.Add(new OracleParameter("p_course_id", OracleDbType.Int32,
                      System.Data.ParameterDirection.Input)).Value = 123;
oraCmd.Parameters.Add(new OracleParameter("p_question",  OracleDbType.Varchar2,
                      System.Data.ParameterDirection.Input)).Value = "question";
oraCmd.Parameters.Add(new OracleParameter("p_postername", OracleDbType.Varchar2,
                      System.Data.ParameterDirection.Input)).Value = "postername";
oraCmd.Parameters.Add(new OracleParameter("p_blog_date", OracleDbType.Date,
                      System.Data.ParameterDirection.Input)).Value = DateTime.Now;
try 
{
    oraCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

Result:

column question format a11;
column postername format a11;

select *
  from forum;

COURSE_ID QUESTION    POSTERNAME  BLOG_DATE         
---------- ----------- ----------- -------------------
       123 question    postername  02-03-2014 12:11:59

It also should be noted that when you execute a stored procedure by calling ExecuteNonQuery() method, the number of affected rows will be -1. It will give you the expected number of affected rows only if you execute a DML(insert, etc.) statement .

OTHER TIPS

Try this:

command.Parameters.Add(new OracleParameter("course_Id",OracleDbType.Number, course_Id)) ;
command.Parameters.Add(new OracleParameter("question",OracleDbType.VarChar, question));
command.Parameters.Add(new OracleParameter( "posterName",OracleDbType.VarChar,posterName));
command.Parameters.Add(new  OracleParameter("blog_date",OracleDbType.DateTime, blog_date));

Try replacing System.Data.DBType with System.Data.OracleClient.OracleType

    command.Parameters.Add("p_course_id", OracleType.Number).Value = course_Id;
    command.Parameters.Add("p_question", OracleType.VarChar).Value = question;
    command.Parameters.Add("p_postername", OracleType.VarChar).Value = posterName;
    command.Parameters.Add("p_blog_date", OracleType.DateTime).Value = blog_date;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top