我一直在尝试使用visual studio 2012在我的C#窗体中调用oracle中的存储过程。我收到以下错误:PLS-00306:调用' GET_ID_BRIEF&的错误数量或类型的参数#39 ;. 我检查了两天,确保所有变量类型和顺序都正确。我在我的项目中使用了20多个存储过程,但没有一个存在执行问题。 我还尝试在SQL Plus命令shell中执行此过程,并获得正确的结果,没有任何错误。
这是程序:
create or replace procedure Get_ID_brief (IDp number, namep out varchar2, curr_pos out varchar2,hire_date out varchar2, morly out varchar2, pos_start out varchar2,done out boolean)
as
begin
done:=true;
select name, position, payment, startdate,hiredate
into namep,curr_pos,morly,pos_start,hire_date
from employees_brief
where ID=IDp;
exception
when no_data_found then done:=false;
end;
/
这是我得到的错误:
ORA-06550: line1, column 7:
PLS-00306: wrong number or types of arguments in call to 'GET_ID_BRIEF'
ORA-06550: line1, column 7:
PL/SQL: Statement ignored
这是产生此错误的C#代码:
private void button1_Click(object sender, EventArgs e)
{
string constr = "DATA SOURCE=localhost:1521/test;PASSWORD=onetwothree;PERSIST SECURITY INFO=True;USER ID=C##kidzclub";
OracleConnection con = new OracleConnection(constr);
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = "Get_ID_brief";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("IDp", OracleDbType.Int16);
cmd.Parameters["IDp"].Direction = ParameterDirection.Input;
cmd.Parameters["IDp"].Value = id;
cmd.Parameters.Add("namep", OracleDbType.NVarchar2);
cmd.Parameters["namep"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("curr_pos", OracleDbType.NVarchar2);
cmd.Parameters["curr_pos"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("hire_date", OracleDbType.NVarchar2);
cmd.Parameters["hire_date"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("morly", OracleDbType.Boolean);
cmd.Parameters["morly"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("pos_start", OracleDbType.NVarchar2);
cmd.Parameters["pos_start"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("done", OracleDbType.Boolean);
cmd.Parameters["done"].Direction = ParameterDirection.Output;
try { cmd.ExecuteNonQuery(); }
catch (OracleException Ex)
{
MessageBox.Show(Ex.Message);
}
Boolean done = Convert.ToBoolean(cmd.Parameters["done"].Value.ToString());
if (done) MessageBox.Show("It Works");
else MessageBox.Show("It did not work");
}
这是我的项目中使用另一个过程的另一个函数的代码,我找不到执行此类错误的任何区别:
private void Button_add_emp_Click(object sender, EventArgs e)
{
string fname = text_fname.Text;
string lname = text_lname.Text;
string pass = text_password.Text;
string position = combo_positions.SelectedValue.ToString();
int pos = Convert.ToInt16(position);
string morly = combo_morly.Text;
string hdate = monthCalendar1.SelectionStart.ToShortDateString();
label_new_emp.Text = hdate;
bool result;
label_new_emp.ForeColor = System.Drawing.Color.Red;
if (fname.Length == 0) {label_new_emp.Text = "Enter the first\nname to continue"; return ;}
if (lname.Length == 0) {label_new_emp.Text = "Enter the last\nname to continue"; return ;}
if (pass.Length == 0) {label_new_emp.Text = "Enter a password\n to continue";return ;}
if (pass.Length < 8) { label_new_emp.Text = "Password must be\nmore than 8 characters"; return; }
if (combo_positions.SelectedIndex == -1) {label_new_emp.Text = "Choose a position\nto continue";return ;}
if (combo_morly.SelectedIndex == -1) {label_new_emp.Text = "Choose Monthly or\nHourly to continue";return ;}
string constr = "DATA SOURCE=localhost:1521/test;PASSWORD=onetwothree;PERSIST SECURITY INFO=True;USER ID=C##kidzclub";
OracleConnection con = new OracleConnection(constr);
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = "new_emp";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("first_namep", OracleDbType.NVarchar2);
cmd.Parameters["first_namep"].Direction = ParameterDirection.Input;
cmd.Parameters["first_namep"].Value = fname;
cmd.Parameters.Add("last_namep", OracleDbType.NVarchar2);
cmd.Parameters["last_namep"].Direction = ParameterDirection.Input;
cmd.Parameters["last_namep"].Value = lname;
cmd.Parameters.Add("position_IDp", OracleDbType.Int16);
cmd.Parameters["position_IDp"].Direction = ParameterDirection.Input;
cmd.Parameters["position_IDp"].Value = pos;
cmd.Parameters.Add("hire_datep", OracleDbType.NVarchar2);
cmd.Parameters["hire_datep"].Direction = ParameterDirection.Input;
cmd.Parameters["hire_datep"].Value = hdate;
cmd.Parameters.Add("monhourly", OracleDbType.NVarchar2);
cmd.Parameters["monhourly"].Direction = ParameterDirection.Input;
cmd.Parameters["monhourly"].Value = morly;
cmd.Parameters.Add("pass", OracleDbType.NVarchar2);
cmd.Parameters["pass"].Direction = ParameterDirection.Input;
cmd.Parameters["pass"].Value = pass;
cmd.Parameters.Add("done", OracleDbType.Boolean);
cmd.Parameters["done"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
result = Convert.ToBoolean(cmd.Parameters["done"].Value.ToString());
if (result) label_new_emp.Text = "Employee Added";
else label_new_emp.Text = "An Error Occured,\n check for duplicate names";
}
这是程序从中获取输出的视图:
create or replace view employees_brief
as
select e.ID,first_name||' '||last_name as name, p.name as position,j.hourly_monthly as Payment, to_char(start_date,'dd/mm/yy') as StartDate, to_char(hire_date,'dd/mm/yy') as HireDate
from employees e, positions p, jobs j
where e.position_ID=p.ID and e.ID=j.employee_ID;
这是我如何测试我的程序:
declare
namep varchar2(25);
curr_pos varchar2(25);
hire_date varchar2(25);
morly boolean;
pos_start varchar2(25);
done boolean;
begin
Get_ID_brief (1, namep , curr_pos ,hire_date, morly,pos_start,done );
dbms_output.put_line(namep);
dbms_output.put_line(curr_pos);
dbms_output.put_line(hire_date);
if(morly=true)then dbms_output.put_line('morly is true');
else dbms_output.put_line('morly is false');end if;
dbms_output.put_line(pos_start);
if(done=true)then dbms_output.put_line('done is true');
else dbms_output.put_line('done is false');end if;
end;
/
这是我得到的正确输出:
Admin Admin
Admin
01/08/14
morly is true
01/08/14
done is true
PL/SQL procedure successfully completed.