调用Oracle存储过程时出错

时间:2014-04-18 20:41:30

标签: c# sql oracle stored-procedures

我收到了一个错误:

  

PLS-00306:调用'SPVALIDATEDBA'时参数的数量或类型错误

尝试从C#函数内部调用存储过程spValidateDBA时

C#代码

string sConnectionString = "Data Source=XE;User ID=system;Password=system;";
            OracleConnection myConnection = new OracleConnection(sConnectionString);
            OracleCommand myCommand = new OracleCommand("spValidateDBA", myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;
            myCommand.CommandText = "spValidateDBA";
            myCommand.Parameters.Add("UserId", OracleDbType.Varchar2, 50);
            myCommand.Parameters["UserId"].Value = txtUsrId.Text.ToUpper().ToString();
            myCommand.Parameters.Add("UserRole", OracleDbType.Varchar2, 50).Direction = ParameterDirection.Output;               
            var rolechk = false;
            string checkrole = "DBA";   
            myConnection.Open();
            myCommand.ExecuteReader();
// this is where i'm getting the error "PLS-00306: wrong number
// or types of arguments in call to 'SPVALIDATEDBA'"

存储过程spValidateDBA

create or replace PROCEDURE spValidateDBA(
    UserId IN VARCHAR2,
    UserRole OUT STRING_ARRAY)
AS
BEGIN
    EXECUTE IMMEDIATE 'select GRANTED_ROLE bulk collect into UserRole from DBA_USERS DU,DBA_ROLE_PRIVS DRP where DU.USERNAME=UserId AND DU.USERNAME=DRP.GRANTEE';
    EXECUTE IMMEDIATE 'select USERNAME into UserIdOut from DBA_USERS where USERNAME=UserId';
END spValidateDBA;

STRING_ARRAY是在此语句中声明的字符串数组类型:

CREATE TYPE STRING_ARRAY AS TABLE OF VARCHAR2(50);

0 个答案:

没有答案