Exception while executing stored procedure odp.net

允我心安 提交于 2020-01-05 09:34:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!