Oracle 更新存储过程无法在 C# 代码中运行
我有以下代码:
try
{
conn.Open();
OracleCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "collikx.webadmin.usp_update_license";
cmd.Parameters.Add(new OracleParameter("licenseSeqNo", OracleDbType.Int32, 30, 228, ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("thirdPartyId", OracleDbType.Int32, 30, 2, ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("licenseNumber", OracleDbType.Varchar2, 12, "tttttttttttt", ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("licenseState", OracleDbType.Char, 2, "CT", ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("licenseLevel", OracleDbType.Varchar2, 2, "E1", ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("licenseType", OracleDbType.Char, 2, "QQ", ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("cutTap", OracleDbType.Char, 1, "Y", ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("status", OracleDbType.Varchar2, 30, "NOTVALID", ParameterDirection.Input));
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
throw;
}
finally { conn.Close(); }
存储过程是:
PROCEDURE usp_update_license( thirdPartyId integer,
licenseSeqNo integer,
licenseNumber VARCHAR2,
licenseState VARCHAR2,
licenseLevel VARCHAR2,
licenseType VARCHAR2,
cutTap VARCHAR2,
status VARCHAR2) AS
begin
update CNTRCTR_LCNS_INFO
set cntrctr_lcns_no = licenseNumber,
lcns_st_cd = licenseState,
certfn_level_type_cd = licenseLevel,
cntrctr_type_cd = licenseType,
cut_tap_authy_ind = cutTap,
stat_type_nm = status
where third_party_id = thirdPartyId and cntrctr_lcns_seq_no = licenseSeqNo
;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
RAISE;
end usp_update_license;
当我执行此操作时,数据库中没有任何变化。我知道它是从 C# 调用的,因为如果我注释掉其中一个参数行,我会收到一条错误,指出没有 enout 参数。但是,C# 代码中的 licenseType 值“QQ”应该违反 FK 约束,但我没有收到任何错误提示。我有其他存储过程以完全相同的方式调用,工作正常...
我应该注意,直接通过 sql Developer 执行存储过程是可行的。
我做错了什么?
I have the following code:
try
{
conn.Open();
OracleCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "collikx.webadmin.usp_update_license";
cmd.Parameters.Add(new OracleParameter("licenseSeqNo", OracleDbType.Int32, 30, 228, ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("thirdPartyId", OracleDbType.Int32, 30, 2, ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("licenseNumber", OracleDbType.Varchar2, 12, "tttttttttttt", ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("licenseState", OracleDbType.Char, 2, "CT", ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("licenseLevel", OracleDbType.Varchar2, 2, "E1", ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("licenseType", OracleDbType.Char, 2, "QQ", ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("cutTap", OracleDbType.Char, 1, "Y", ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("status", OracleDbType.Varchar2, 30, "NOTVALID", ParameterDirection.Input));
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
throw;
}
finally { conn.Close(); }
The stored proc is:
PROCEDURE usp_update_license( thirdPartyId integer,
licenseSeqNo integer,
licenseNumber VARCHAR2,
licenseState VARCHAR2,
licenseLevel VARCHAR2,
licenseType VARCHAR2,
cutTap VARCHAR2,
status VARCHAR2) AS
begin
update CNTRCTR_LCNS_INFO
set cntrctr_lcns_no = licenseNumber,
lcns_st_cd = licenseState,
certfn_level_type_cd = licenseLevel,
cntrctr_type_cd = licenseType,
cut_tap_authy_ind = cutTap,
stat_type_nm = status
where third_party_id = thirdPartyId and cntrctr_lcns_seq_no = licenseSeqNo
;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
RAISE;
end usp_update_license;
When I execute this, nothing in the database changes. I know it's getting called from C# because if i comment out one of the parameter lines I get an error that there are not enout params. However, the value "QQ" for licenseType in the C# code should violate a FK contraint but I get no error telling me that. I have other stored procs called exactly the same way that work fine...
I should note that executing the stored proc directly through sql developer works.
What am i doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的参数无序:
切换
到
You are not getting the where Clause to match (默认按顺序绑定)
在 ODP 中,您可以更改此设置。BindByName = True 覆盖默认的 BindByName =false
EDIT
你会想要
cmd.BindByName = True;
(默认为 FALSE,会导致混乱和问题!)
You have the parameters out of order:
switch
to
You are not getting the where clause to match (binds by order by default)
in ODP you can change this .BindByName = True to overwrite the default BindByName =false
EDIT
You will want to
cmd.BindByName = True;
(this defaults to FALSE and causes the confusion and problem!)
可能是Where子句不匹配...
尝试从Oracle本身执行存储过程。
May be the Where Clause is not matching...
Try executing the store procedure from Oracle itself.