gpt4 book ai didi

c# - ORA-06502 : PL/SQL: numeric or value error: character string buffer too small exception from C# code

转载 作者:太空狗 更新时间:2023-10-29 17:41:57 26 4
gpt4 key购买 nike

我正在尝试使用来自 asp.net 上的 # 代码的输入和输出参数执行一些 oracle pl/sql 过程。我想从 out 参数中检索值。但是当我执行时,我得到一个 oracle 异常,如“ORA-06502:PL/SQL:数字或值错误:字符串缓冲区太小”。我现在该怎么办?请帮助我。

代码:

using Oracle.DataAccess.Client;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Activity.Account
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SuccessLabel.Visible = false;
FailureLabel.Visible = false;
}

protected void Create_user(object sender, EventArgs e)
{
var id="";
string oradb = "Data Source=OracleServerHost;User ID=scott;password=tiger";
using (OracleConnection conn = new OracleConnection(oradb))
{
try
{
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "create_users_372640";
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter p1 = new OracleParameter("u_user_id", UserIDTextBox.Text.TrimEnd());
OracleParameter p2 = new OracleParameter("u_First", FirstNameTextBox.Text.TrimEnd());
OracleParameter p3 = new OracleParameter("u_Last", LastNameTextBox.Text.TrimEnd());
OracleParameter p4 = new OracleParameter("u_Email", EmailIDTextBox.Text.TrimEnd());
OracleParameter p5 = new OracleParameter("u_password", PasswordTextBox.Text.TrimEnd());
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
cmd.Parameters.Add(p3);
cmd.Parameters.Add(p4);
cmd.Parameters.Add(p5);
OracleCommand cmd_chk = new OracleCommand();
cmd_chk.Connection = conn;
cmd_chk.CommandText = "check_user_372640";
cmd_chk.CommandType = CommandType.StoredProcedure;
OracleParameter p6 = new OracleParameter("user_id", UserIDTextBox.Text.TrimEnd());
cmd_chk.Parameters.Add(p6);
cmd_chk.Parameters.Add("id", OracleDbType.Varchar2).Direction = ParameterDirection.Output;
conn.Open();
cmd_chk.ExecuteNonQuery();
id=(string)cmd_chk.Parameters["id"].Value;
//OracleDataReader rd = cmd_chk.ExecuteReader();
if (id != null && id != "")
{
//rd.Read();
SuccessLabel.Visible = false;
FailureLabel.Visible = true;
}
else
{
cmd.ExecuteNonQuery();
SuccessLabel.Visible = true;
FailureLabel.Visible = false;
}
}catch(Exception){
Console.WriteLine("SQL Exception Occured");
}
}

}
}
}

我的 oracle 程序是:

create or replace procedure check_user_372640(
user_id in varchar2,
id out varchar2
)
as
u_id varchar2(20);
begin
select user_id into u_id from ACTIVITY_USERS_372640 where user_id=user_id;
id:=u_id;
end;

最佳答案

它现在对我有用。错误是我将参数“Id”声明为 varchar2。但我没有给出任何尺寸。现在我已经为参数声明了最大大小并且它工作正常。

 cmd_chk.Parameters.Add("id", OracleDbType.Varchar2,32767).Direction = ParameterDirection.Output;

关于c# - ORA-06502 : PL/SQL: numeric or value error: character string buffer too small exception from C# code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21899765/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com