问题
I've executed around 5 stored procedures with the below code (parameters will vary with respect to Stored procedure). Those are working fine except the below SP. output of the below code is: p_out=2 p_msg= 'exception while execution'
In SP, it going to exception block. Can anybody let me know the exact issue.
Code:
Database db = DatabaseFactory.CreateDatabase("OracleDBConnectionString");
OracleCommand oracleCommand = new OracleCommand();
oracleCommand.CommandType = CommandType.StoredProcedure;
oracleCommand.CommandText = "PCK_ADMIN.PROC_VALIDATE_USER";
oracleCommand.Parameters.Add("P_USERNAME", OracleDbType.Varchar2).Value = "ddd";
oracleCommand.Parameters.Add("P_out", OracleDbType.Int32).Direction = ParameterDirection.Output;
oracleCommand.Parameters.Add("P_msg", OracleDbType.Varchar2).Direction = ParameterDirection.Output;
db.ExecuteNonQuery(oracleCommand);
string outValue = oracleCommand.Parameters["P_out"].Value.ToString();
string outMsg = oracleCommand.Parameters["P_msg"].Value.ToString();
Stored Procedure is:
create or replace
PACKAGE BODY PCK_ADMIN AS
PROCEDURE PROC_VALIDATE_USER
(P_USERNAME IN USR_USER.USERNAME%TYPE,
P_out OUT NUMBER,
P_msg OUT VARCHAR2) AS
v_cnt NUMBER(5):=0;
BEGIN
P_OUT := 0;
Select count(USERID) into v_cnt from usr_user
where username = P_USERNAME;
IF v_cnt = 0 then
p_out := 0;
p_msg := 'Record doesnot exists';
ELSE
p_out := 1;
p_msg := 'Record already exists';
END IF;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
p_out := 2;
p_msg := 'exception while execution';
END PROC_VALIDATE_USER;
END PCK_ADMIN;
Table Structure of usr_user is
USERNAME VARCHAR2(20 BYTE)
USERID NUMBER
回答1:
I specified size for P_msg output parameter and it worked.
oracleCommand.Parameters.Add("P_msg", OracleDbType.Varchar2, 50).Direction = ParameterDirection.Output;
来源:https://stackoverflow.com/questions/27032296/exception-while-executing-stored-procedure-odp-net