Need Help! I am new in executing function in a stored procedure package, I need to execute this package using oracle C# windows application..
CREATE OR REPLACE PACKAGE TSCBE1005_PKG IS
FUNCTION TSCBE1005_001_FNC( P_BLD_LVL_CD IN VARCHAR2,
P_IN_DATE IN VARCHAR2,
P_IN_PC IN VARCHAR2,
P_BLD_SPEC_NO IN OUT VARCHAR2,
P_BLD_SPEC_NO_SEQ IN OUT NUMBER,
P_ART_NO IN OUT VARCHAR2`,
P_CURE_KIBN IN OUT VARCHAR2,
P_CURE_LR_KBN IN OUT VARCHAR2,
P_HINMEI IN OUT VARCHAR2,
P_TIRE_SIZE IN OUT VARCHAR2,
P_E4_MARK IN OUT NUMBER,
P_SECTOR_NO IN OUT VARCHAR2,
P_UPLATE_NO IN OUT VARCHAR2,
P_LPLATE_NO IN OUT VARCHAR2,
P_BLADER_NO IN OUT VARCHAR2,
P_MAX_TCLC_SINGLE IN OUT NUMBER,
P_TCLC_UNIT_SINGLE IN OUT VARCHAR2,
P_MAX_IP_SINGLE IN OUT NUMBER,
P_IP_UNIT_SINGLE IN OUT VARCHAR2,
P_PR IN OUT NUMBER,
P_MSG IN OUT VARCHAR2
) RETURN NUMBER;
PROCEDURE TSCBE1005_002_PRC( P_RET_DATA IN NUMBER,
P_INFO1 IN VARCHAR2,
P_INFO2 IN VARCHAR2,
P_IN_PC IN VARCHAR2
) ;
END TSCBE1005_PKG;
When I'm running it to Oracle, using script below, it's actually successful.
variable O_BLD_SPEC_NO VARCHAR2(7)
variable O_BLD_SPEC_NO_SEQ NUMBER
variable O_ART_NO VARCHAR2(5)
variable O_CURE_KIBN VARCHAR2(4)
variable O_CURE_LR_KBN VARCHAR2(1)
variable O_HINMEI VARCHAR2(50)
variable O_TIRE_SIZE VARCHAR2(20)
variable O_E4_MARK NUMBER
variable O_SECTOR_NO VARCHAR2(6)
variable O_UPLATE_NO VARCHAR2(6)
variable O_LPLATE_NO VARCHAR2(6)
variable O_BLADER_NO VARCHAR2(7)
variable O_MAX_TCLC_SINGLE NUMBER
variable O_TCLC_UNIT_SINGLE VARCHAR2(3)
variable O_MAX_IO_SINGLE NUMBER
variable O_IO_UNIT_SINGLE VARCHAR2(3)
variable O_PR NUMBER
variable O_MSG VARCHAR2(20)
variable ret varchar2(100)
execute :ret := TSCBE1005_PKG.TSCBE1005_001_FNC('R123456789','20170124120644','YRC07400',:O_BLD_SPEC_NO,:O_BLD_SPEC_NO_SEQ,:O_ART_NO,:O_CURE_KIBN,:O_CURE_LR_KBN,:O_HINMEI,:O_TIRE_SIZE,:O_E4_MARK,:O_SECTOR_NO,:O_UPLATE_NO,:O_LPLATE_NO,:O_BLADER_NO,:O_MAX_TCLC_SINGLE,:O_TCLC_UNIT_SINGLE,:O_MAX_IO_SINGLE,:O_IO_UNIT_SINGLE,:O_PR,:O_MSG)
;
print O_BLD_SPEC_NO
print O_BLD_SPEC_NO_SEQ
print O_ART_NO
print O_CURE_KIBN
print O_CURE_LR_KBN
print O_HINMEI
print O_TIRE_SIZE
print O_E4_MARK
print O_SECTOR_NO
print O_UPLATE_NO
print O_LPLATE_NO
print O_BLADER_NO
print O_MAX_TCLC_SINGLE
print O_TCLC_UNIT_SINGLE
print O_MAX_IO_SINGLE
print O_IO_UNIT_SINGLE
print O_PR
print O_MSG
print ret
I tried to execute this in C# oracle using below code,
using (OracleConnection objConn = new OracleConnection("User id=skraze; Password=skraze; Data source=database"))
{
objConn.Open();
OracleCommand objCmd = new OracleCommand();
objCmd.Connection = objConn;
objCmd.CommandText = "TSCBE1005_PKG.TSCBE1005_001_FNC";
objCmd.CommandType = CommandType.StoredProcedure;
OracleParameter P_BLD_LVL_CD = new OracleParameter();
P_BLD_LVL_CD.ParameterName = ":P_BLD_LVL_CD";
P_BLD_LVL_CD.OracleType = OracleType.VarChar;
P_BLD_LVL_CD.Direction = ParameterDirection.Input;
P_BLD_LVL_CD.Value = "R123456789";
objCmd.Parameters.Add(P_BLD_LVL_CD);
OracleParameter P_IN_DATE = new OracleParameter();
P_IN_DATE.ParameterName = ":P_IN_DATE";
P_IN_DATE.OracleType = OracleType.VarChar;
P_IN_DATE.Direction = ParameterDirection.Input;
P_IN_DATE.Value = "20170124120644";
objCmd.Parameters.Add(P_IN_DATE);
OracleParameter P_IN_PC = new OracleParameter();
P_IN_PC.ParameterName = ":P_IN_PC";
P_IN_PC.OracleType = OracleType.VarChar;
P_IN_PC.Direction = ParameterDirection.Input;
P_IN_PC.Value = "YRC07400";
objCmd.Parameters.Add(P_IN_PC);
OracleParameter P_BLD_SPEC_NO = new OracleParameter();
P_BLD_SPEC_NO.ParameterName = ":P_BLD_SPEC_NO";
P_BLD_SPEC_NO.OracleType = OracleType.VarChar;
P_BLD_SPEC_NO.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_BLD_SPEC_NO);
OracleParameter P_BLD_SPEC_NO_SEQ = new OracleParameter();
P_BLD_SPEC_NO_SEQ.ParameterName = ":P_BLD_SPEC_NO_SEQ";
P_BLD_SPEC_NO_SEQ.OracleType = OracleType.Number;
P_BLD_SPEC_NO_SEQ.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_BLD_SPEC_NO_SEQ);
OracleParameter P_ART_NO = new OracleParameter();
P_ART_NO.ParameterName = ":P_ART_NO";
P_ART_NO.OracleType = OracleType.VarChar;
P_ART_NO.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_ART_NO);
OracleParameter P_CURE_KIBN = new OracleParameter();
P_CURE_KIBN.ParameterName = ":P_CURE_KIBN";
P_CURE_KIBN.OracleType = OracleType.VarChar;
P_CURE_KIBN.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_CURE_KIBN);
OracleParameter P_CURE_LR_KBN = new OracleParameter();
P_CURE_LR_KBN.ParameterName = ":P_CURE_LR_KBN";
P_CURE_LR_KBN.OracleType = OracleType.VarChar;
P_CURE_LR_KBN.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_CURE_LR_KBN);
OracleParameter P_HINMEI = new OracleParameter();
P_HINMEI.ParameterName = ":P_HINMEI";
P_HINMEI.OracleType = OracleType.VarChar;
P_HINMEI.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_HINMEI);
OracleParameter P_TIRE_SIZE = new OracleParameter();
P_TIRE_SIZE.ParameterName = ":P_TIRE_SIZE";
P_TIRE_SIZE.OracleType = OracleType.VarChar;
P_TIRE_SIZE.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_TIRE_SIZE);
OracleParameter P_E4_MARK = new OracleParameter();
P_E4_MARK.ParameterName = ":P_E4_MARK";
P_E4_MARK.OracleType = OracleType.Number;
P_E4_MARK.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_E4_MARK);
OracleParameter P_SECTOR_NO = new OracleParameter();
P_SECTOR_NO.ParameterName = ":P_SECTOR_NO";
P_SECTOR_NO.OracleType = OracleType.VarChar;
P_SECTOR_NO.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_SECTOR_NO);
OracleParameter P_UPLATE_NO = new OracleParameter();
P_UPLATE_NO.ParameterName = ":P_UPLATE_NO";
P_UPLATE_NO.OracleType = OracleType.VarChar;
P_UPLATE_NO.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_UPLATE_NO);
OracleParameter P_LPLATE_NO = new OracleParameter();
P_LPLATE_NO.ParameterName = ":P_LPLATE_NO";
P_LPLATE_NO.OracleType = OracleType.VarChar;
P_LPLATE_NO.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_LPLATE_NO);
OracleParameter P_BLADER_NO = new OracleParameter();
P_BLADER_NO.ParameterName = ":P_BLADER_NO";
P_BLADER_NO.OracleType = OracleType.VarChar;
P_BLADER_NO.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_BLADER_NO);
OracleParameter P_MAX_TCLC_SINGLE = new OracleParameter();
P_MAX_TCLC_SINGLE.ParameterName = ":P_MAX_TCLC_SINGLE";
P_MAX_TCLC_SINGLE.OracleType = OracleType.Number;
P_MAX_TCLC_SINGLE.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_MAX_TCLC_SINGLE);
OracleParameter P_TCLC_UNIT_SINGLE = new OracleParameter();
P_TCLC_UNIT_SINGLE.ParameterName = ":P_TCLC_UNIT_SINGLE";
P_TCLC_UNIT_SINGLE.OracleType = OracleType.VarChar;
P_TCLC_UNIT_SINGLE.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_TCLC_UNIT_SINGLE);
OracleParameter P_MAX_IO_SINGLE = new OracleParameter();
P_MAX_IO_SINGLE.ParameterName = ":P_MAX_IO_SINGLE";
P_MAX_IO_SINGLE.OracleType = OracleType.Number;
P_MAX_IO_SINGLE.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_MAX_IO_SINGLE);
OracleParameter P_IO_UNIT_SINGLE = new OracleParameter();
P_IO_UNIT_SINGLE.ParameterName= ":P_IO_UNIT_SINGLE";
P_IO_UNIT_SINGLE.OracleType = OracleType.VarChar;
P_IO_UNIT_SINGLE.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_IO_UNIT_SINGLE);
OracleParameter P_PR = new OracleParameter();
P_PR.ParameterName = ":P_PR";
P_PR.OracleType = OracleType.Number;
P_PR.Direction = ParameterDirection.Input;
objCmd.Parameters.Add(P_PR);
OracleParameter W_BLD_SPEC_NO = new OracleParameter();
W_BLD_SPEC_NO.OracleType = OracleType.VarChar;
W_BLD_SPEC_NO.Size = 7;
W_BLD_SPEC_NO.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_BLD_SPEC_NO);
OracleParameter W_BLD_SPEC_NO_SEQ = new OracleParameter();
W_BLD_SPEC_NO_SEQ.OracleType = OracleType.Number;
W_BLD_SPEC_NO_SEQ.Size = 1;
W_BLD_SPEC_NO_SEQ.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_BLD_SPEC_NO_SEQ);
OracleParameter W_ART_NO = new OracleParameter();
W_ART_NO.OracleType = OracleType.VarChar;
W_ART_NO.Size = 5;
W_ART_NO.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_ART_NO);
OracleParameter W_CURE_KIBN = new OracleParameter();
W_CURE_KIBN.OracleType = OracleType.VarChar;
W_CURE_KIBN.Size = 4;
W_CURE_KIBN.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_CURE_KIBN);
OracleParameter W_CURE_LR_KBN = new OracleParameter();
W_CURE_LR_KBN.OracleType = OracleType.VarChar;
W_CURE_LR_KBN.Size = 1;
W_CURE_LR_KBN.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_CURE_LR_KBN);
OracleParameter W_HINMEI = new OracleParameter();
W_HINMEI.OracleType = OracleType.VarChar;
W_HINMEI.Size = 50;
W_HINMEI.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_HINMEI);
OracleParameter W_TIRE_SIZE = new OracleParameter();
W_TIRE_SIZE.OracleType = OracleType.VarChar;
W_TIRE_SIZE.Size = 20;
W_TIRE_SIZE.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_TIRE_SIZE);
OracleParameter W_E4_MARK = new OracleParameter();
W_E4_MARK.OracleType = OracleType.Number;
W_E4_MARK.Size = 1;
W_E4_MARK.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_E4_MARK);
OracleParameter W_SECTOR_NO = new OracleParameter();
W_SECTOR_NO.OracleType = OracleType.VarChar;
W_SECTOR_NO.Size = 6;
W_SECTOR_NO.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_SECTOR_NO);
OracleParameter W_UPLATE_NO = new OracleParameter();
W_UPLATE_NO.OracleType = OracleType.VarChar;
W_UPLATE_NO.Size = 6;
W_UPLATE_NO.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_UPLATE_NO);
OracleParameter W_LPLATE_NO = new OracleParameter();
W_LPLATE_NO.OracleType = OracleType.VarChar;
W_LPLATE_NO.Size = 6;
W_LPLATE_NO.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_LPLATE_NO);
OracleParameter W_BLADER_NO = new OracleParameter();
W_BLADER_NO.OracleType = OracleType.VarChar;
W_BLADER_NO.Size = 7;
W_BLADER_NO.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_BLADER_NO);
OracleParameter W_MAX_TCLC_SINGLE = new OracleParameter();
W_MAX_TCLC_SINGLE.OracleType = OracleType.Number;
W_MAX_TCLC_SINGLE.Size = 1;
W_MAX_TCLC_SINGLE.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_MAX_TCLC_SINGLE);
OracleParameter W_TCLC_UNIT_SINGLE = new OracleParameter();
W_TCLC_UNIT_SINGLE.OracleType = OracleType.VarChar;
W_TCLC_UNIT_SINGLE.Size = 3;
W_TCLC_UNIT_SINGLE.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_TCLC_UNIT_SINGLE);
OracleParameter W_MAX_IO_SINGLE = new OracleParameter();
W_MAX_IO_SINGLE.OracleType = OracleType.Number;
W_MAX_IO_SINGLE.Size = 1;
W_MAX_IO_SINGLE.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_MAX_IO_SINGLE);
OracleParameter W_IO_UNIT_SINGLE = new OracleParameter();
W_IO_UNIT_SINGLE.OracleType = OracleType.VarChar;
W_IO_UNIT_SINGLE.Size = 3;
W_IO_UNIT_SINGLE.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_IO_UNIT_SINGLE);
OracleParameter W_PR = new OracleParameter();
W_PR.OracleType = OracleType.Number;
W_PR.Size = 1;
W_PR.Direction = ParameterDirection.ReturnValue;
objCmd.Parameters.Add(W_PR);
objCmd.ExecuteNonQuery();
objConn.Close();
}
But I'm still getting error
{"ORA-06550: line 1, column 34:\nPLS-00103: Encountered the symbol \"=\" when expecting one of the following:\n\n . ( * # % & = - + ; < / > at in is mod not rem\n <an exponent (**)> <> or != or ~= >= <= <> and or like\n between || indicator\n"}
Please, I hope anyone could help me :(
This looks wrong
P_BLD_LVL_CD.ParameterName = ":P_BLD_LVL_CD";
^
The colon is used for identifying placeholders in a SQL string. Actual parameter name should be
P_BLD_LVL_CD.ParameterName = "P_BLD_LVL_CD";
Also ParameterDirection.ReturnValue is used for the return value only. So there should only be one such parameter per function call. You appear to be using it for all the IN OUT parameters. That is wrong.
For IN OUT parameters you need to use ParameterDirection.InputOutput.
Incidentally a function with IN OUT parameters is poor PL/SQL practice, but I guess there's not much you can do about that.
So, TSCBE1005_001_FNC is a function which takes three IN (read only) parameters and eighteen IN OUT (read/write) parameters. Therefore your call needs:
one parameter with ParameterDirection.ReturnValue
three parameters with ParameterDirection.Input
eighteen parameters with ParameterDirection.InputOutput
I never used objCmd.CommandType = CommandType.StoredProcedure;
I always use this syntax:
objCmd.CommandText = "BEGIN :res := TSCBE1005_PKG.TSCBE1005_001_FNC(:P_BLD_LVL_CD, :P_IN_DATE, ...); END;";
objCmd.CommandType = CommandType.Text;
Then your parameter declaration is wrong.
P_SECTOR_NO.Direction = ParameterDirection.Input;
ParameterDirection has to match signature of your function, i.e. ReturnValue or Input or Output (not used in your example) or InputOutput
The type is also wrong:
P_SECTOR_NO.OracleType = OracleType.VarChar;
You must use OracleDbType, see OracleDbType Enumeration. For mapping between OracleDbType and .NET type see C#: Oracle Data Type Equivalence with OracleDbType
btw, you can put this all in one command, e.g.
cmd.Parameters.Add("P_BLD_LVL_CD", OracleDbType.Varchar2, ParameterDirection.Input).Value = "R035570412";
Be aware in case of ParameterDirection.Output you have to set DbType separately. Also in case of OracleDbType.Varchar2 you must specify the size and an initial value:
cmd.Parameters.Add("parName", OracleDbType.Varchar2, 240, null, ParameterDirection.Output);
cmd.Parameters("parName").DbType = DbType.String;
Related
I am stuck on an issue for past few days.The issue is detailed below:
There are 15 input params (of type int and varchar), 1 record type param and 5 output params for this oracle package.
It was observed that while passing record type parameter to the package this exception is thrown,work fine with those packages with out record type param.
Exception Thrown:-Unable to cast object of type 'System.Int32' to type
'System.Array'. Stack Trace:- at
Oracle.DataAccess.Client.OracleParameter.SetStatus(Int32 arraySize) at
Oracle.DataAccess.Client.OracleParameter.ResetCtx(Int32 arraySize) at
Oracle.DataAccess.Client.OracleParameter.PreBind(OracleConnection
conn, IntPtr errCtx, Int32 arraySize) at
Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery() at
POC_App.DataformatConverter.ExecuteCreateSOPackage()
What I have tried:
public static void ExecuteCreateSOPackage()
{
string constr = EstablishDBConnection();
OracleConnection con = new OracleConnection(constr);
con.Open();
OracleCommand cmd = new OracleCommand("APPS.XX_OM_CREATE_SO_TEST.create_sale_orders", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.BindByName = true;
cmd.ArrayBindCount = 100;
OracleParameter retVal = new OracleParameter("retVal", OracleDbType.RefCursor);
retVal.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(retVal);
OracleParameter paramPersonId = setInputParameters("p_person_id", OracleDbType.Int32, 0);
paramPersonId.Value = 31842;
cmd.Parameters.Add(paramPersonId);
<likewise 14 more input params >
---------------------------------
//Record type parameter..
OracleParameter p_so_lines_tab = new OracleParameter();
p_so_lines_tab.ParameterName = "p_so_lines_tab";
p_so_lines_tab.OracleDbType = OracleDbType.NVarchar2;
p_so_lines_tab.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
p_so_lines_tab.Size = 3;
p_so_lines_tab.Direction = ParameterDirection.Input;
OracleParameter P_SO_LINES_TAB_ITEM = new OracleParameter();
P_SO_LINES_TAB_ITEM.ParameterName = "p_so_lines_tab_item";
P_SO_LINES_TAB_ITEM.OracleDbType = OracleDbType.NVarchar2;
P_SO_LINES_TAB_ITEM.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
P_SO_LINES_TAB_ITEM.Size = 1000;
P_SO_LINES_TAB_ITEM.Direction = ParameterDirection.Input;
OracleParameter QUANTITY = new OracleParameter();
QUANTITY.ParameterName = "quantity";
QUANTITY.OracleDbType = OracleDbType.Int32;
QUANTITY.Value = 1;
OracleParameter QUANTITY_UOM = new OracleParameter();
QUANTITY_UOM.ParameterName = "quantity_uom";
QUANTITY_UOM.OracleDbType = OracleDbType.Varchar2;
QUANTITY_UOM.Value = "Ea";
OracleParameter ITEM_ID = new OracleParameter();
ITEM_ID.ParameterName = "item_id";
ITEM_ID.OracleDbType = OracleDbType.Int32;
ITEM_ID.Value = 162744;
OracleParameter PROMISE_DATE = new OracleParameter();
PROMISE_DATE.ParameterName = "promise_date";
PROMISE_DATE.OracleDbType = OracleDbType.Date;
PROMISE_DATE.Value = "2016-04-01T08:58:50.649Z";
OracleParameter SCHEDULE_SHIP_DATE = new OracleParameter();
SCHEDULE_SHIP_DATE.ParameterName = "schedule_ship_date";
SCHEDULE_SHIP_DATE.OracleDbType = OracleDbType.Date;
SCHEDULE_SHIP_DATE.Value = "2016-04-01T08:58:50.649Z";
OracleParameter CURRENCY_CODE = new OracleParameter();
CURRENCY_CODE.ParameterName = "currency_code";
CURRENCY_CODE.OracleDbType = OracleDbType.Varchar2;
CURRENCY_CODE.Value = "USD";
OracleParameter UNIT_SELLING_PRICE = new OracleParameter();
UNIT_SELLING_PRICE.ParameterName = "unit_selling_price";
UNIT_SELLING_PRICE.OracleDbType = OracleDbType.Int32;
UNIT_SELLING_PRICE.Value = 200;
OracleParameter SALESREP_ID = new OracleParameter();
SALESREP_ID.ParameterName = "salesrep_id";
SALESREP_ID.OracleDbType = OracleDbType.Int32;
SALESREP_ID.Value = 1412;
P_SO_LINES_TAB_ITEM.Value = new object[] { QUANTITY, QUANTITY_UOM, ITEM_ID, PROMISE_DATE, SCHEDULE_SHIP_DATE, CURRENCY_CODE, UNIT_SELLING_PRICE, SALESREP_ID };
//Adding to outer most collection
p_so_lines_tab.Value = P_SO_LINES_TAB_ITEM;
cmd.Parameters.Add(p_so_lines_tab);
cmd.Parameters.Add("x_time_stamp", OracleDbType.TimeStamp, ParameterDirection.Output);
cmd.Parameters.Add("x_order_header_id", OracleDbType.Int32, ParameterDirection.Output);
cmd.Parameters.Add("x_order_number", OracleDbType.Int32, ParameterDirection.Output);
cmd.Parameters.Add("x_return_code", OracleDbType.Varchar2, ParameterDirection.Output);
cmd.Parameters.Add("x_return_msg", OracleDbType.Varchar2, ParameterDirection.Output);
try
{
cmd.ExecuteNonQuery();
}
catch (Exception exp)
{
string str = exp.StackTrace.ToString();
string msg = exp.Message.ToString();
}
}
You have this OracleParameter:
OracleParameter P_SO_LINES_TAB_ITEM = new OracleParameter();
P_SO_LINES_TAB_ITEM.ParameterName = "p_so_lines_tab_item";
P_SO_LINES_TAB_ITEM.OracleDbType = OracleDbType.NVarchar2;
P_SO_LINES_TAB_ITEM.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
P_SO_LINES_TAB_ITEM.Size = 1000;
P_SO_LINES_TAB_ITEM.Direction = ParameterDirection.Input;
Value of P_SO_LINES_TAB_ITEM must be a list of plain text (i.e. NVARCHAR2 as you declared by property OracleDbType). However, you try to use a list of OracleParameter objects.
P_SO_LINES_TAB_ITEM.Value = new object[] { QUANTITY, QUANTITY_UOM, ITEM_ID, PROMISE_DATE, SCHEDULE_SHIP_DATE, CURRENCY_CODE, UNIT_SELLING_PRICE, SALESREP_ID };
This is not possible, you cannot make nested parameters.
Got a solution for my problem .We can pass a collection of data by setting the oracle.Dbtype as NVarchar as shown below.
var commandObject = new OracleCommand
{
Connection = con,
CommandText = "Your Packge Name",
CommandType = CommandType.StoredProcedure
};
commandObject.Connection.Open();
commandObject.Parameters.Add("param1", OracleDbType.Int32, ParameterDirection.Input).Value = some int value;
commandObject.Parameters.Add("param2", OracleDbType.Int32, ParameterDirection.Input).Value = some int value;
commandObject.Parameters.Add("param3", OracleDbType.Int32, ParameterDirection.Input).Value = some int value;
commandObject.Parameters.Add("p_xml_type", OracleDbType.NVarchar2, ParameterDirection.Input).Value =some collection
commandObject.Parameters.Add("param returncode", OracleDbType.Varchar2, 200).Direction = "some string value";
commandObject.ExecuteNonQuery();
The collection being set is in xml format of type string and in the oracle package the parameter has been defined as shown below.
p_xml_type IN CLOB
Stored procedure:
CREATE OR REPLACE PROCEDURE insertMovie(
p_m_id IN MOVIE.M_ID%TYPE,
p_movie_name IN MOVIE.MOVIE_NAME%TYPE,
p_year IN MOVIE.YEAR%TYPE,
p_category IN MOVIE.CATEGORY%TYPE)
IS
BEGIN
INSERT INTO MOVIE ("M_ID", "MOVIE_NAME", "YEAR", "CATEGORY")
VALUES (p_m_id, p_movie_name,p_year, p_category);
END;
/
This is the procedure I have created to insert data into the movie table. Now I am trying to call it from by C#. I have tried the following code but it's not working.
A little help in this regard will be much appreciated. Thank you
private void button1_Click(object sender, EventArgs e)
{
dbConnection conObj = new dbConnection();
OracleConnection theConn = conObj.connFunc();
String p_m_id, p_movie_name, p_year, p_category;
p_m_id = movie_id.Text;
p_movie_name = movie_name.Text;
p_year = year.Text;
p_category = category.Text;
OracleParameter parChoiceIn = new OracleParameter();
OracleParameter parDataIn = new OracleParameter();
OracleParameter parOut = new OracleParameter();
parChoiceIn.ParameterName = "p_m_id";
parChoiceIn.OracleType = OracleType.Number;
parChoiceIn.Size = 32;
parChoiceIn.Direction = System.Data.ParameterDirection.Input;
parChoiceIn.Value = p_m_id;
parDataIn.ParameterName = "p_movie_name";
parDataIn.OracleType = OracleType.VarChar;
parDataIn.Size = 32;
parDataIn.Direction = System.Data.ParameterDirection.Input;
parDataIn.Value = p_movie_name;
parDataIn.ParameterName = "p_year";
parDataIn.OracleType = OracleType.Number;
parDataIn.Size = 32;
parDataIn.Direction = System.Data.ParameterDirection.Input;
parDataIn.Value = p_year;
parDataIn.ParameterName = "p_category";
parDataIn.OracleType = OracleType.VarChar;
parDataIn.Size = 32;
parDataIn.Direction = System.Data.ParameterDirection.Input;
parDataIn.Value = p_category;
OracleCommand cmd = theConn.CreateCommand();
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "insertMovie";
cmd.Parameters.Add(parChoiceIn);
cmd.Parameters.Add(parDataIn);
cmd.Parameters.Add(parOut);
theConn.Open();
OracleDataAdapter adapter = new OracleDataAdapter(cmd);
DataSet myset = new DataSet("theResCur");
adapter.Fill(myset);
theGrid.DataSource = myset;
theGrid.DataSource = myset.Tables[0];
theConn.Close();
}
}
You are creating a parOut parameter but never initializing it.
Also, you are redefining the parDataIn parameter three times, doing so, your OracleCommand only receives the last defined parameter p_category.
I do not understand what is your intent in the last part of your code. If you want to simply call the stored procedure, maybe you should try this:
private void button1_Click(object sender, EventArgs e)
{
dbConnection conObj = new dbConnection();
OracleConnection theConn = conObj.connFunc();
String p_m_id, p_movie_name, p_year, p_category;
p_m_id = movie_id.Text;
p_movie_name = movie_name.Text;
p_year = year.Text;
p_category = category.Text;
theConn.Open();
OracleCommand cmd = theConn.CreateCommand();
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "insertMovie";
cmd.Connection = theConn;
OracleParameter parChoiceIn = new OracleParameter();
OracleParameter parDataIn = new OracleParameter();
parChoiceIn.ParameterName = "p_m_id";
parChoiceIn.OracleType = OracleType.Number;
parChoiceIn.Size = 32;
parChoiceIn.Direction = System.Data.ParameterDirection.Input;
parChoiceIn.Value = p_m_id;
cmd.Parameters.Add(parChoiceIn);
parDataIn.ParameterName = "p_movie_name";
parDataIn.OracleType = OracleType.VarChar;
parDataIn.Size = 32;
parDataIn.Direction = System.Data.ParameterDirection.Input;
parDataIn.Value = p_movie_name;
cmd.Parameters.Add(parDataIn);
parDataIn = new OracleParameter();
parDataIn.ParameterName = "p_year";
parDataIn.OracleType = OracleType.Number;
parDataIn.Size = 32;
parDataIn.Direction = System.Data.ParameterDirection.Input;
parDataIn.Value = p_year;
cmd.Parameters.Add(parDataIn);
parDataIn = new OracleParameter();
parDataIn.ParameterName = "p_category";
parDataIn.OracleType = OracleType.VarChar;
parDataIn.Size = 32;
parDataIn.Direction = System.Data.ParameterDirection.Input;
parDataIn.Value = p_category;
cmd.Parameters.Add(parDataIn);
cmd.ExecuteNonQuery();
theConn.Close();
}
I'm having difficulty trying to call my DBA's function inside C#. It works fine in the Oracle query browser, however when I attempt to execute it in C# it fails.
The most common error is : "ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 1"
I've attempted to increase the size of the C# parameters but to no success. Not sure what I'm doing wrong.
C# Code :
string returnValue = string.Empty;
using (OracleConnection cn = new OracleConnection("ConnectionString"))
{
using (OracleCommand cmd = new OracleCommand())
{
cmd.Connection = cn;
cmd.CommandText = "package.function";
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter param1 = new OracleParameter();
OracleParameter param2 = new OracleParameter();
OracleParameter param3 = new OracleParameter();
OracleParameter param4 = new OracleParameter();
OracleParameter param5 = new OracleParameter();
param1.OracleDbType = OracleDbType.Varchar2;
param1.Direction = ParameterDirection.Input;
param1.Value = "Test808";
param1.ParameterName = "var1";
//param1.Size = 2000;
param2.OracleDbType = OracleDbType.Varchar2;
param2.Direction = ParameterDirection.Input;
param2.Value = "68B54814";
param2.ParameterName = "var2";
//param2.Size = 2000;
param3.OracleDbType = OracleDbType.Varchar2;
param3.Direction = ParameterDirection.Input;
param3.Value = "71839";
param3.ParameterName = "var4";
//param3.Size = 2000;
param4.OracleDbType = OracleDbType.Varchar2;
param4.Direction = ParameterDirection.Input;
param4.Value = 55 ;
param4.ParameterName = "var4";
//param4.Size = 2000;
param5.OracleDbType = OracleDbType.Varchar2;
param5.Direction = ParameterDirection.ReturnValue;
param5.ParameterName = "return";
//param5.Size = 2000;
cmd.Parameters.Add(param1);
cmd.Parameters.Add(param2);
cmd.Parameters.Add(param3);
cmd.Parameters.Add(param4);
cmd.Parameters.Add(param5);
try
{
cn.Open();
cmd.ExecuteNonQuery();
returnValue = cmd.Parameters["return"].Value.ToString();
}
catch
{
}
finally
{
cn.Close();
}
}
}
return returnValue;
Function Header:
FUNCTION create_rec
(p_mims_pallet_id varchar2
,p_item_no varchar2
,p_packer_id varchar2
,p_tare_wt varchar2
)
return varchar2
1st time trying Oracle calls. Never had an issue with SQL. The parameter.Size is commented out for not seeming to do anything.
Was able to get it working by removing the individual Parameters and creating them the Parameter.Add method.
Working Code:
string returnValue = string.Empty;
using (OracleConnection cn = new OracleConnection("ConString"))
{
using (OracleCommand cmd = new OracleCommand())
{
cmd.Connection = cn;
cmd.CommandText = "package.function";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("rv", OracleDbType.Varchar2, 200, "", ParameterDirection.ReturnValue);
cmd.Parameters.Add("var1", OracleDbType.Varchar2, 20, "Test808", ParameterDirection.Input);
cmd.Parameters.Add("var2", OracleDbType.Varchar2, 20, "68B54814", ParameterDirection.Input);
cmd.Parameters.Add("var3", OracleDbType.Varchar2, 20, "71839", ParameterDirection.Input);
cmd.Parameters.Add("var4", OracleDbType.Decimal, 55, ParameterDirection.Input);
try
{
cn.Open();
cmd.ExecuteNonQuery();
returnValue = cmd.Parameters["rv"].Value.ToString();
}
catch
{
}
finally
{
cn.Close();
}
}
}
return returnValue;
I fixed this issue by changing its syntax. It was giving numeric or value overflow error if we use below syntax:
cmd.Parameters.Add("strSqlMsg", OracleDbType.Varchar2, 255, ParameterDirection.Output);
Which I changed to below and it worked.
cmd.Parameters.Add("strSqlMsg", OracleDbType.Varchar2, ParameterDirection.Output).Size=255;
Hope this will work for you.
Thanks.
Atul
string strRetrun = string.Empty;
using (OracleConnection objCon = (OracleConnection)_connection)
{
using (OracleCommand objCom = new OracleCommand())
{
objCom.Connection = objCon;
objCom.CommandText = "SAM.PKG_SAM_ECH.F_FUND_TRANSFER_TYPE";
objCom.CommandType = CommandType.StoredProcedure;
OracleParameter codeReturn = new OracleParameter("RETURN", OracleType.VarChar, 1000);
codeReturn.Direction = ParameterDirection.ReturnValue;
OracleParameter code1 = new OracleParameter("V_RECORD_ID", OracleType.Number);
code1.Direction = ParameterDirection.Input;
if (obj.RecordId != null)
code1.Value = obj.RecordId;
else
code1.Value = DBNull.Value;
OracleParameter code2 = new OracleParameter("V_DEBIT_APAC", OracleType.VarChar, 200);
code2.Direction = ParameterDirection.Input;
if (obj.P_BENEF_APAC != null)
code2.Value = obj.P_BENEF_APAC;
else
code2.Value = DBNull.Value;
OracleParameter code3 = new OracleParameter("V_ACCOUNT_TYPE", OracleType.VarChar, 200);
code3.Direction = ParameterDirection.Input;
if (obj.BenfAccType != null)
code3.Value = obj.BenfAccType;
else
code3.Value = DBNull.Value;
OracleParameter code4 = new OracleParameter("V_IFSC_CODE", OracleType.VarChar, 200);
code4.Direction = ParameterDirection.Input;
if (obj.IFSC != null)
code4.Value = obj.IFSC;
else
code4.Value = DBNull.Value;
objCom.Parameters.Add(codeReturn);
objCom.Parameters.Add(code1);
objCom.Parameters.Add(code2);
objCom.Parameters.Add(code3);
objCom.Parameters.Add(code4);
try
{
objCon.Open();
objCom.ExecuteNonQuery();
strRetrun = objCom.Parameters["RETURN"].Value.ToString();
}
catch
{
}
finally
{
objCon.Close();
}
}
}
return strRetrun;
To everybody who is wondering why the answer from Tim B is working.
It's the order of the parameters!
The return parameter of the function has to be bound first!
Also for the other Parameters the order counts and not the name.
The first version with creating the parameters individually, would be OK if "param5" would have been added as first object in to the collection.
I got stuck on this for while :-(
I used stored proceture in the Oracle. How can I use out parameteres of the SP in C# code?
I use the following code for it:
OracleSP
PROCEDURE TABMPWORKREQUEST_INS(INTWORKREQUEST_ IN NUMBER, VCWORKREQUESTNUMBER_ OUT VARCHAR2,
INTREQUESTEDBY_ IN NUMBER, INTWORKTYPE_ IN NUMBER,INTACTIONTYPE_ IN NUMBER,
INTPRIORITY_ IN NUMBER, INTRECORDID_ IN NUMBER, INTPERMITREQUIRED_ IN NUMBER, VCINSPECTIONREQUIRED_ IN CHAR,
VCLASTUSERID_ IN VARCHAR2, INTCOSTCENTRECODE_ IN NUMBER, VCBUDGETHEAD_ IN VARCHAR2
, VCREFERENCEWORKORDERNUMBER_ IN VARCHAR2, VCJOBDESCRIPTION_ IN VARCHAR2,
VCSTATUS_ IN CHAR, VCHISTORYFLAG_ IN CHAR, VCREASONCODE_ IN VARCHAR2
, VCMSSNUMBER_ IN VARCHAR2, INTAUTHORIZELEVEL_ IN NUMBER, INTPRINTFLAG_ IN NUMBER,
INTINSPECTIONFLAG_ IN NUMBER, INTDAYNUMBER_ IN NUMBER, INTDURATION_ IN NUMBER, INTPROGRESS_ IN NUMBER,
INTWORKSHOPFLAG_ IN CHAR)
IS
EXISTANCE number;
UID_ VARCHAR(5);
SS varchar2(20);
BEGIN
SELECT COUNT(*) into EXISTANCE FROM TABMPWORKREQUEST WHERE INTWORKREQUEST = INTWORKREQUEST_ ;
IF VCLASTUSERID_ = '0' THEN
UID_ := 'U2';
ELSE
UID_ := VCLASTUSERID_;
END IF;
select GetWorkOrderNumber(INTREQUESTEDBY_) INTO SS from dual ;
VCWORKREQUESTNUMBER_ :=SS;
INSERT INTO TABMPWORKREQUEST
VALUES( CMMS.SEQTABMPWORKREQUEST.NEXTVAL , SS , sysdate , INTrequestedby_ ,
INTworktype_ , INTactiontype_ , INTpriority_ , Intrecordid_ , Intpermitrequired_ , Vcinspectionrequired_ ,
Vclastuserid_ , SYSDATE , sysdate , INTcostcentrecode_ , Vcbudgethead_ , sysdate ,
Vcreferenceworkordernumber_ , Vcjobdescription_ , '01' , Vchistoryflag_ , Vcreasoncode_ ,
sysdate , sysdate , Vcmssnumber_ , Intauthorizelevel_ , Intprintflag_ , Intinspectionflag_ ,
Intdaynumber_ , Intduration_ , Intprogress_ , Intworkshopflag_ );
END TABMPWORKREQUEST_INS;
and c# code
public bool InsertMpWORKREQUEST(ClsFieldsMpWORKREQUEST fieldsMpWORKREQUEST)
{
string DTBDDATETIME;
if (fieldsMpWORKREQUEST.DTBDDATETIME != null)
{
DTBDDATETIME = String.Format("{0:dd/MM/yyyy HH:mm:ss}", fieldsMpWORKREQUEST.DTBDDATETIME);
DTBDDATETIME = "TO_DATE('" + DTBDDATETIME + "', 'MM/DD/YYYY HH24:MI:SS')";
}
else
{
DTBDDATETIME = "NULL";
}
string DateExpire = string.Empty;
if (fieldsMpWORKREQUEST.DTEXPIRYDATE != null)
{
DateExpire = String.Format("{0:dd/MM/yyyy HH:mm:ss}", fieldsMpWORKREQUEST.DTEXPIRYDATE);
DateExpire = "TO_DATE('" + DateExpire + "', 'MM/DD/YYYY HH24:MI:SS')";
}
else
{
DateExpire = "NULL";
}
string DtStartDate;
if (fieldsMpWORKREQUEST.DTSTARTDATE != null)
{
DtStartDate = String.Format("{0:dd/MM/yyyy HH:mm:ss}", fieldsMpWORKREQUEST.DTSTARTDATE);
DtStartDate = "TO_DATE('" + DtStartDate + "', 'MM/DD/YYYY HH24:MI:SS')";
}
else
{
DtStartDate = "NULL";
}
string DtComplementationDate;
if (fieldsMpWORKREQUEST.DTCOMPLETIONDATE != null)
{
DtComplementationDate = String.Format("{0:dd/MM/yyyy HH:mm:ss}", fieldsMpWORKREQUEST.DTCOMPLETIONDATE);
DtComplementationDate = "TO_DATE('" + DtComplementationDate + "', 'MM/DD/YYYY HH24:MI:SS')";
}
else
{
DtComplementationDate = "NULL";
}
OracleConnection cn = new OracleConnection(this.GetConnectionString());
OracleCommand cmd = new OracleCommand("CMMS_MPWORKREQUEST_PKG.TABMPWORKREQUEST_INS", cn);
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter INTWORKREQUEST = new OracleParameter();
INTWORKREQUEST.ParameterName = "INTWORKREQUEST_";
INTWORKREQUEST.OracleType = OracleType.Number;
INTWORKREQUEST.Direction = ParameterDirection.Input;
INTWORKREQUEST.Value = fieldsMpWORKREQUEST.INTWORKREQUEST;
cmd.Parameters.Add(INTWORKREQUEST);
// cmd.Parameters.AddWithValue("VCWORKREQUESTNUMBER_", fieldsMpWORKREQUEST.VCWORKREQUESTNUMBER).Direction=ParameterDirection.Output;
OracleParameter requestNo = new OracleParameter();
requestNo.ParameterName = "VCWORKREQUESTNUMBER_";
requestNo.OracleType = OracleType.VarChar;
requestNo.Size = 14;
requestNo.Direction = ParameterDirection.Output;
cmd.Parameters.Add(requestNo);
OracleParameter INTREQUESTEDBY = new OracleParameter();
INTREQUESTEDBY.ParameterName = "INTREQUESTEDBY_";
INTREQUESTEDBY.OracleType = OracleType.Number;
INTREQUESTEDBY.Direction = ParameterDirection.Input;
INTREQUESTEDBY.Value = fieldsMpWORKREQUEST.INTREQUESTEDBY.INTSECTIONID;
cmd.Parameters.Add(INTREQUESTEDBY);
OracleParameter INTWORKTYPE = new OracleParameter();
INTWORKTYPE.ParameterName = "INTWORKTYPE_";
INTWORKTYPE.OracleType = OracleType.Number;
INTWORKTYPE.Direction = ParameterDirection.Input;
INTWORKTYPE.Value = fieldsMpWORKREQUEST.INTREQUESTEDBY.INTSECTIONID;
cmd.Parameters.Add(INTWORKTYPE);
OracleParameter INTACTIONTYPE = new OracleParameter();
INTACTIONTYPE.ParameterName = "INTACTIONTYPE_";
INTACTIONTYPE.OracleType = OracleType.Number;
INTACTIONTYPE.Direction = ParameterDirection.Input;
INTACTIONTYPE.Value = fieldsMpWORKREQUEST.INTACTIONTYPE.INTSECTIONID;
cmd.Parameters.Add(INTACTIONTYPE);
OracleParameter INTPRIORITY = new OracleParameter();
INTPRIORITY.ParameterName = "INTPRIORITY_";
INTPRIORITY.OracleType = OracleType.Number;
INTPRIORITY.Direction = ParameterDirection.Input;
INTPRIORITY.Value = fieldsMpWORKREQUEST.INTPRIORITY.INTGENERALCODE;
cmd.Parameters.Add(INTPRIORITY);
OracleParameter INTRECORDID = new OracleParameter();
INTRECORDID.ParameterName = "INTRECORDID_";
INTRECORDID.OracleType = OracleType.Number;
INTRECORDID.Direction = ParameterDirection.Input;
INTRECORDID.Value = fieldsMpWORKREQUEST.INTRECORDID;
cmd.Parameters.Add(INTRECORDID);
OracleParameter INTPERMITREQUIRED = new OracleParameter();
INTPERMITREQUIRED.ParameterName = "INTPERMITREQUIRED_";
INTPERMITREQUIRED.OracleType = OracleType.Number;
INTPERMITREQUIRED.Direction = ParameterDirection.Input;
INTPERMITREQUIRED.Value = fieldsMpWORKREQUEST.INTPERMITREQUIRED;
cmd.Parameters.Add(INTPERMITREQUIRED);
OracleParameter VCINSPECTIONREQUIRED = new OracleParameter();
VCINSPECTIONREQUIRED.ParameterName = "VCINSPECTIONREQUIRED_";
VCINSPECTIONREQUIRED.OracleType = OracleType.Char;
VCINSPECTIONREQUIRED.Direction = ParameterDirection.Input;
VCINSPECTIONREQUIRED.Value = fieldsMpWORKREQUEST.VCINSPECTIONREQUIRED;
cmd.Parameters.Add(VCINSPECTIONREQUIRED);
OracleParameter VCLASTUSERID = new OracleParameter();
VCLASTUSERID.ParameterName = "VCLASTUSERID_";
VCLASTUSERID.OracleType = OracleType.VarChar;
VCLASTUSERID.Direction = ParameterDirection.Input;
VCLASTUSERID.Value = fieldsMpWORKREQUEST.VCLASTUSERID;
cmd.Parameters.Add(VCLASTUSERID);
OracleParameter INTCOSTCENTRECODE = new OracleParameter();
INTCOSTCENTRECODE.ParameterName = "INTCOSTCENTRECODE_";
INTCOSTCENTRECODE.OracleType = OracleType.Number;
INTCOSTCENTRECODE.Direction = ParameterDirection.Input;
INTCOSTCENTRECODE.Value = fieldsMpWORKREQUEST.INTCOSTCENTRECODE.INTGENERALCODE;
cmd.Parameters.Add(INTCOSTCENTRECODE);
OracleParameter vCBUDGETHEAD = new OracleParameter();
vCBUDGETHEAD.ParameterName = "VCBUDGETHEAD_";
vCBUDGETHEAD.OracleType = OracleType.VarChar;
vCBUDGETHEAD.Direction = ParameterDirection.Input;
vCBUDGETHEAD.Value = fieldsMpWORKREQUEST.VCBUDGETHEAD;
cmd.Parameters.Add(vCBUDGETHEAD);
OracleParameter VCREFERENCEWORKORDERNUMBER = new OracleParameter();
VCREFERENCEWORKORDERNUMBER.ParameterName = "VCREFERENCEWORKORDERNUMBER_";
VCREFERENCEWORKORDERNUMBER.OracleType = OracleType.VarChar;
VCREFERENCEWORKORDERNUMBER.Direction = ParameterDirection.Input;
VCREFERENCEWORKORDERNUMBER.Value = fieldsMpWORKREQUEST.VCREFERENCEWORKORDERNUMBER;
cmd.Parameters.Add(VCREFERENCEWORKORDERNUMBER);
OracleParameter VCJOBDESCRIPTION = new OracleParameter();
VCJOBDESCRIPTION.ParameterName = "VCJOBDESCRIPTION_";
VCJOBDESCRIPTION.OracleType = OracleType.VarChar;
VCJOBDESCRIPTION.Direction = ParameterDirection.Input;
VCJOBDESCRIPTION.Value = fieldsMpWORKREQUEST.VCJOBDESCRIPTION;
cmd.Parameters.Add(VCJOBDESCRIPTION);
OracleParameter VCSTATUS = new OracleParameter();
VCSTATUS.ParameterName = "VCSTATUS_";
VCSTATUS.OracleType = OracleType.Char;
VCSTATUS.Direction = ParameterDirection.Input;
VCSTATUS.Value = fieldsMpWORKREQUEST.VCSTATUS;
cmd.Parameters.Add(VCSTATUS);
OracleParameter VCHISTORYFLAG = new OracleParameter();
VCHISTORYFLAG.ParameterName = "VCHISTORYFLAG_";
VCHISTORYFLAG.OracleType = OracleType.Char;
VCHISTORYFLAG.Direction = ParameterDirection.Input;
VCHISTORYFLAG.Value = fieldsMpWORKREQUEST.VCHISTORYFLAG;
cmd.Parameters.Add(VCHISTORYFLAG);
OracleParameter VCREASONCODE = new OracleParameter();
VCREASONCODE.ParameterName = "VCREASONCODE_";
VCREASONCODE.OracleType = OracleType.VarChar;
VCREASONCODE.Direction = ParameterDirection.Input;
VCREASONCODE.Value = fieldsMpWORKREQUEST.VCREASONCODE;
cmd.Parameters.Add(VCREASONCODE);
OracleParameter VCMSSNUMBER = new OracleParameter();
VCMSSNUMBER.ParameterName = "VCMSSNUMBER_";
VCMSSNUMBER.OracleType = OracleType.VarChar;
VCMSSNUMBER.Direction = ParameterDirection.Input;
VCMSSNUMBER.Value = fieldsMpWORKREQUEST.VCMSSNUMBER;
cmd.Parameters.Add(VCMSSNUMBER);
OracleParameter INTAUTHORIZELEVEL = new OracleParameter();
INTAUTHORIZELEVEL.ParameterName = "INTAUTHORIZELEVEL_";
INTAUTHORIZELEVEL.OracleType = OracleType.Number;
INTAUTHORIZELEVEL.Direction = ParameterDirection.Input;
INTAUTHORIZELEVEL.Value = fieldsMpWORKREQUEST.INTAUTHORIZELEVEL;
cmd.Parameters.Add(INTAUTHORIZELEVEL);
OracleParameter INTPRINTFLAG = new OracleParameter();
INTPRINTFLAG.ParameterName = "INTPRINTFLAG_";
INTPRINTFLAG.OracleType = OracleType.Number;
INTPRINTFLAG.Direction = ParameterDirection.Input;
INTPRINTFLAG.Value = fieldsMpWORKREQUEST.INTPRINTFLAG;
cmd.Parameters.Add(INTPRINTFLAG);
OracleParameter INTINSPECTIONFLAG = new OracleParameter();
INTINSPECTIONFLAG.ParameterName = "INTINSPECTIONFLAG_";
INTINSPECTIONFLAG.OracleType = OracleType.Number;
INTINSPECTIONFLAG.Direction = ParameterDirection.Input;
INTINSPECTIONFLAG.Value = fieldsMpWORKREQUEST.INTINSPECTIONFLAG;
cmd.Parameters.Add(INTINSPECTIONFLAG);
OracleParameter INTDAYNUMBER = new OracleParameter();
INTDAYNUMBER.ParameterName = "INTDAYNUMBER_";
INTDAYNUMBER.OracleType = OracleType.Number;
INTDAYNUMBER.Direction = ParameterDirection.Input;
INTDAYNUMBER.Value = fieldsMpWORKREQUEST.INTDAYNUMBER;
cmd.Parameters.Add(INTDAYNUMBER);
OracleParameter INTDURATION = new OracleParameter();
INTDURATION.ParameterName = "INTDURATION_";
INTDURATION.OracleType = OracleType.Number;
INTDURATION.Direction = ParameterDirection.Input;
INTDURATION.Value = fieldsMpWORKREQUEST.INTDURATION;
cmd.Parameters.Add(INTDURATION);
OracleParameter INTPROGRESS = new OracleParameter();
INTPROGRESS.ParameterName = "INTPROGRESS_";
INTPROGRESS.OracleType = OracleType.Number;
INTPROGRESS.Direction = ParameterDirection.Input;
INTPROGRESS.Value = fieldsMpWORKREQUEST.INTPROGRESS;
cmd.Parameters.Add(INTPROGRESS);
OracleParameter INTWORKSHOPFLAG = new OracleParameter();
INTWORKSHOPFLAG.ParameterName = "INTWORKSHOPFLAG_";
INTWORKSHOPFLAG.OracleType = OracleType.Char;
INTWORKSHOPFLAG.Direction = ParameterDirection.Input;
INTWORKSHOPFLAG.Value = fieldsMpWORKREQUEST.INTWORKSHOPFLAG;
cmd.Parameters.Add(INTWORKSHOPFLAG);
string requestNo2 = string.Empty;
int rowEfect = 0;
try
{
cn.Open();
rowEfect = cmd.ExecuteNonQuery();
requestNo2 = cmd.Parameters["VCWORKREQUESTNUMBER_"].Value.ToString();
}
catch (Exception)
{
throw;
}
finally
{
if (cn.State != ConnectionState.Closed) cn.Close();
}
return rowEfect > 0;
}
But I get the following error:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'TABMPWORKREQUEST_INS'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
How can I fix this problem?
The objects in the MSFT System.Data namespace relating to Oracle have been deprecated:
http://msdn.microsoft.com/en-us/library/77d8yct7.aspx
But there is a generic System.Data.OleDB namespace:
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbparameter.direction(v=VS.71).aspx
The Command object has a parameters collection. Each parameter has several properties, including a direction property. When you set that property to output, you can examine its value after issuing the command.
A third-party provider for Oracle should offer something similar.
P.S. I haven't used the OleDB namespace in a very long time -- but recall that the parameters had to be added to the Parameters collection in the same order in which they appear in the SP's signature. Be sure to set the appropriate datatype for each parameter and provide the length of any text values being passed.
P.P.S. It looks as though you're adding the same parameter to the collection twice; is one of these supposed to be commented out?
cmd.Parameters.AddWithValue("VCWORKREQUESTNUMBER_",fieldsMpWORKREQUEST.VCWORKREQUESTNUMBER).Direction=ParameterDirection.Output;
OracleParameter requestNo = new OracleParameter();
requestNo.ParameterName = "VCWORKREQUESTNUMBER_";
requestNo.OracleType = OracleType.VarChar;
requestNo.Size = 14;
requestNo.Direction = ParameterDirection.Output;
cmd.Parameters.Add(requestNo);
Now I know this has been asked before. But I've made doubly sure that all parameters are correct and there are no typos. I still get the error. Could somebody please guide me here? I am nearing my wit's end!
CREATE OR REPLACE PROCEDURE VWT.WUA_DELETE_FP_REQUEST
(i_pLDAPUserName IN varchar2,
i_pIReasonCode IN number,
i_pLastName IN varchar2,
i_pFirstName IN varchar2,
i_pDealerID IN number,
i_pAddr1 IN varchar2,
i_pAddr2 IN varchar2,
i_pCity IN varchar2,
i_pState IN varchar2,
i_pZip IN varchar2,
i_pBusinessEmail IN varchar2,
i_pBusinessPhone IN varchar2,
i_pReviewDate IN Date,
i_pReviewedByWhom IN varchar2,
i_pDealersRepID IN varchar2,
i_pComments IN varchar2,
i_pPrivacyUsageFlag IN varchar2,
i_pDealersBranchID IN varchar2,
i_pPrivacyUsageDate IN date,
i_pMarketingFlag IN varchar2,
i_pMarketingDate IN date,
i_pWorkCountry IN varchar2,
i_pOperator IN varchar2,
o_return_status OUT integer,
o_error_desc OUT varchar2
)
========================================================================
Code to run the procedure
OracleParameter ldapUserName = new OracleParameter
("i_pLDAPUserName", OracleType.VarChar, 1024);
ldapUserName.Direction = ParameterDirection.Input;
ldapUserName.Value = ldapUserName_;
command.Parameters.Add(ldapUserName);
OracleParameter reasonCode = new OracleParameter
("i_pIReasonCode", OracleType.Number);
reasonCode.Direction = ParameterDirection.Input;
reasonCode.Value = reasonCode_;
command.Parameters.Add(reasonCode);
OracleParameter lastName = new OracleParameter
("i_pLastName", OracleType.VarChar, 1024);
lastName.Direction = ParameterDirection.Input;
lastName.Value = userDetail.LastName ?? String.Empty;
command.Parameters.Add(lastName);
OracleParameter firstName = new OracleParameter
("i_pFirstName", OracleType.VarChar, 1024);
firstName.Direction = ParameterDirection.Input;
firstName.Value = userDetail.FirstName ?? String.Empty;
command.Parameters.Add(firstName);
OracleParameter dealerID = new OracleParameter
("i_pDealerID", OracleType.Number);
dealerID.Direction = ParameterDirection.Input;
dealerID.Value =
Int32.Parse(String.IsNullOrEmpty(userDetail.DealerID) ? "0" : userDetail.DealerID);
command.Parameters.Add(dealerID);
OracleParameter address1 = new OracleParameter
("i_pAddr1", OracleType.VarChar, 1024);
address1.Direction = ParameterDirection.Input;
address1.Value = userDetail.WorkAddress1 ?? String.Empty;
command.Parameters.Add(address1);
OracleParameter address2 = new OracleParameter
("i_pAddr2", OracleType.VarChar, 1024);
address2.Direction = ParameterDirection.Input;
address1.Value = userDetail.WorkAddress2 ?? String.Empty;
command.Parameters.Add(address2);
OracleParameter city = new OracleParameter
("i_pCity", OracleType.VarChar, 1024);
city.Direction = ParameterDirection.Input;
city.Value = userDetail.City ?? String.Empty;
command.Parameters.Add(city);
OracleParameter state = new OracleParameter
("i_pState", OracleType.VarChar, 1024);
state.Direction = ParameterDirection.Input;
state.Value = userDetail.State ?? String.Empty;
command.Parameters.Add(state);
OracleParameter zip = new OracleParameter
("i_pZip", OracleType.VarChar, 1024);
zip.Direction = ParameterDirection.Input;
zip.Value = userDetail.Zip ?? String.Empty;
command.Parameters.Add(zip);
OracleParameter email = new OracleParameter
("i_pBusinessEmail", OracleType.VarChar, 1024);
email.Direction = ParameterDirection.Input;
email.Value = userDetail.EMail ?? String.Empty;
command.Parameters.Add(email);
OracleParameter phone = new OracleParameter
("i_pBusinessPhone", OracleType.VarChar, 1024);
phone.Direction = ParameterDirection.Input;
phone.Value = userDetail.Phone ?? String.Empty;
command.Parameters.Add(phone);
OracleParameter reviewDate = new OracleParameter
("i_pReviewDate", OracleType.DateTime);
reviewDate.Direction = ParameterDirection.Input;
reviewDate.Value = userDetail.ReviewedDate ?? (object)DBNull.Value;
command.Parameters.Add(reviewDate);
OracleParameter reviewedbyWhom = new OracleParameter
("i_pReviewedByWhom", OracleType.VarChar, 1024);
reviewedbyWhom.Direction = ParameterDirection.Input;
reviewedbyWhom.Value = userDetail.ReviewedByWhom ?? String.Empty;
command.Parameters.Add(reviewedbyWhom);
OracleParameter repID = new OracleParameter
("i_pDealersRepID", OracleType.VarChar, 1024);
repID.Direction = ParameterDirection.Input;
repID.Value = userDetail.RepID ?? String.Empty;
command.Parameters.Add(repID);
OracleParameter comments = new OracleParameter
("i_pComments", OracleType.VarChar, 1024);
comments.Direction = ParameterDirection.Input;
comments.Value = userDetail.Comments ?? String.Empty + comments_;
command.Parameters.Add(comments);
OracleParameter privacyUsageFlag = new OracleParameter
("i_pPrivacyUsageFlag", OracleType.VarChar, 1024);
privacyUsageFlag.Direction = ParameterDirection.Input;
privacyUsageFlag.Value = userDetail.PrivacyAndUsageReadFlag ?? String.Empty;
command.Parameters.Add(privacyUsageFlag);
OracleParameter dealersBranchID = new OracleParameter
("i_pDealersBranchID", OracleType.VarChar, 1024);
dealersBranchID.Direction = ParameterDirection.Input;
dealersBranchID.Value = userDetail.DealerBranchID ?? String.Empty;
command.Parameters.Add(dealersBranchID);
OracleParameter privacyUsageDate = new OracleParameter
("i_pPrivacyUsageDate", OracleType.DateTime);
privacyUsageDate.Direction = ParameterDirection.Input;
privacyUsageDate.Value =
userDetail.PrivacyAndUsageReadDate ??(object)DBNull.Value;
command.Parameters.Add(privacyUsageDate);
OracleParameter marketingFlag = new OracleParameter
("i_pMarketingFlag", OracleType.VarChar, 1024);
marketingFlag.Direction = ParameterDirection.Input;
marketingFlag.Value = userDetail.SendMarketingEmailFlag ?? String.Empty;
command.Parameters.Add(marketingFlag);
OracleParameter marketingDate = new OracleParameter
("i_pMarketingDate", OracleType.DateTime);
marketingDate.Direction = ParameterDirection.Input;
marketingDate.Value =
userDetail.SendMarketingEmailDate ?? (object)DBNull.Value;
command.Parameters.Add(marketingDate);
OracleParameter country = new OracleParameter
("i_pWorkCountry", OracleType.VarChar, 1024);
country.Direction = ParameterDirection.Input;
country.Value = userDetail.Country ?? String.Empty;
command.Parameters.Add(country);
OracleParameter oper = new OracleParameter
("i_pOperator", OracleType.VarChar, 1024);
oper.Direction = ParameterDirection.Input;
oper.Value = operator_;
command.Parameters.Add(oper);
OracleParameter returnStatus = new OracleParameter
("o_return_status", OracleType.Int16);
returnStatus.Direction = ParameterDirection.Output;
command.Parameters.Add(returnStatus);
OracleParameter errorDesc = new OracleParameter
("o_error_desc", OracleType.VarChar, 1024);
errorDesc.Direction = ParameterDirection.Output;
command.Parameters.Add(errorDesc);
Without a specific error that's occuring, its hard to give a specific answer. The code you've posted could be correct. There's nothing I see that is wrong in all scenarios. However, here are a few places I would start looking.
Is your command statement formatted properly? Do all the VarChar parameters accept 1024 characters? Are any of your strings going into a VarChar column longer than 1024? Is the returnStatus type of Int16 correct?
Anyway, those are some places to start, if you post some more detailed information on the issue, you may get some more responses.
I looked at your code and didn't see anything suspicious.
In similar circumstances I'd do a very stupid test: comment out all the parameters except the first one both in the procedure declaration and in the code running it, then test: if there's an error, you'll know that it's with the first parameter; if no error shows, then uncomment the second parameter in the procedure and in the code.
I know it's stupid, time consuming and annoying, but if you really feel you're closed in a corner, this could give you a more precise hint about where the problem is.
DealerID is declared as Number, but passed as string.
I blame the scrollbars, didn't see the Int32.Parse()
No experience with .Net but I wonder if OracleType.Int16 is the correct datatype for the INTEGER parameter (which according to http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oracletype(VS.71).aspx, being a NUMBER, expects a OracleType.Number)?
OracleType.Int16: "This is not a native Oracle data type, but is provided to improve performance when binding input parameters."