无法在.net中获取Oracle的参数

无法在.net中获取Oracle的参数,.net,plsql,.net,Plsql,正如我在标题中所说的,问题是在.net中oracle of procedure的-out参数为null,尽管该参数是在pl/sql测试中分配的。Out参数数据类型为nvarchar2。我尝试将该值更改为int,效果很好。但我需要从程序返回文本!!!问题是什么?顺便说一句,我使用Oracle.DataAccess.Client; 代码如下: private void OKButton_Click(object sender, EventArgs e) { float cur_rate;

正如我在标题中所说的,问题是在.net中oracle of procedure的-out参数为null,尽管该参数是在pl/sql测试中分配的。Out参数数据类型为nvarchar2。我尝试将该值更改为int,效果很好。但我需要从程序返回文本!!!问题是什么?顺便说一句,我使用Oracle.DataAccess.Client; 代码如下:

private void OKButton_Click(object sender, EventArgs e)
{
    float cur_rate;
    decimal value;
    if (!String.IsNullOrEmpty(RateTxtBox.Text) && decimal.TryParse(RateTxtBox.Text, out value))
    {
    cur_rate = float.Parse(RateTxtBox.Text);
    con = new OracleConnection(conStr);
    con.Open();
    cmd = con.CreateCommand();
    cmd.BindByName = true;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = schema_name + ".CACCRUEMENT_INS";
    cmd.Parameters.Add("p_check_info_id", OracleDbType.Int32, header_id, ParameterDirection.Input);
    cmd.Parameters.Add("p_calculate_on", OracleDbType.Date, DateTime.Parse(dateTimePicker1.Text), ParameterDirection.Input);
    cmd.Parameters.Add("p_curr_id", OracleDbType.Decimal, CurrencyCombobox.SelectedValue, ParameterDirection.Input);
    cmd.Parameters.Add("p_cur_rate", OracleDbType.Decimal, Decimal.Parse(RateTxtBox.Text), ParameterDirection.Input);
    cmd.Parameters.Add("p_result", OracleDbType.NVarchar2).Direction = ParameterDirection.Output;
    //cmd.Parameters.Add("p_result", OracleDbType.NVarchar2,ParameterDirection.Output);
    cmd.ExecuteNonQuery();
    string result = cmd.Parameters["p_result"].Value.ToString();
    MessageBox.Show(result);
    Thread.Sleep(2);
    this.Close();
    }
    else
    {
        MessageBox.Show("Invalid data format!");
    }
}
Pl/sql程序:

create or replace procedure CACCRUEMENT_INS(
p_check_info_id in number,
p_calculate_on in date,
p_curr_id in number,
p_cur_rate in number,
p_result out varchar2
) is

v_Accruemtnt number;
v_rate number;
v_cur_rate_in_check_info number;
Last_accruemet_date date;
monthes_bwn_last_adj_n_chck number;
next_check date;
check_info_rate number;
begin
select c.next_check 
into next_check 
from check_info c 
where c.id_check_info = p_check_info_id;
begin 
  select max(c.calculate_on) 
  into Last_accruemet_date 
  from Caccruement c 
  where c.fk_check_info = p_check_info_id
  group by c.fk_check_info;
  exception when no_data_found then
  begin 
    select max(c.calculate_on_date) 
    into Last_accruemet_date 
    from check_info_lines  c 
    where c.fk_check_info = p_check_info_id 
    group by c.fk_check_info;
  exception when no_data_found then
    p_result:='Adjustment is not calculated!';
    goto l_EndOfLoop;
  end;   
end;
select ci.curency_rate 
into check_info_rate from check_info ci where ci.id_check_info = p_check_info_id;
select c.rate 
into v_rate 
from Check_Info c 
where c.id_check_info = p_check_info_id;
monthes_bwn_last_adj_n_chck:=MONTHS_BETWEEN(next_check,Last_accruemet_date);
IF(monthes_bwn_last_adj_n_chck>round(MONTHS_BETWEEN(p_calculate_on,Last_accruemet_date),3))
THEN
  select c.curency_rate 
  into v_cur_rate_in_check_info 
  from check_info c 
  where c.id_check_info = p_check_info_id;
  --v_rate:=round((v_rate/v_cur_rate_in_check_info),3);  
v_Accruemtnt := round(v_rate/check_info_rate * MONTHS_BETWEEN(p_calculate_on, Last_accruemet_date)*p_cur_rate,3) ;
insert 
into CAccruement(Id_Accruemtnt,Calculate_On,Accruemtnt,Fk_Check_Info,Cu_Id,Cu_Rate,Calculation_Date,Accruemtnt_Kzt) 
values (accruement_seq.nextval,p_calculate_on,round(v_Accruemtnt/p_cur_rate,3),p_check_info_id,p_curr_id,p_cur_rate,Sysdate,v_Accruemtnt);
update check_info c 
set c.total_accumulated = c.total_accumulated+v_Accruemtnt 
where c.id_check_info = p_check_info_id;
END IF; 
 COMMIT; 
 p_result:='Operation complited successfully';
 update_total_accumulated(p_check_info_id);
<<l_EndOfLoop>>
  ROLLBACK;
  EXCEPTION
WHEN OTHERS
THEN
  DBMS_OUTPUT.PUT_LINE(SQLERRM);
  ROLLBACK;    
end CACCRUEMENT_INS;
首先,尝试使用db类型Varchar2而不是NVarchar2

第二,如果您仍然没有得到该值,请尝试以下操作以获得该值
在最后一行抛出OracleNullValue Excaption。好的,可能是null。您能否尝试在程序开始时为p_结果变量赋值?除此之外,在使用诸如max之类的组函数时,您永远不会得到未找到数据的异常。 cmd.Parameters.Add("p_result", OracleDbType.NVarchar2,ParameterDirection.Output); var value = cmd.Parameters["p_result"].Value; var str = (OracleString) value; str.Value; //This is the string