如何动态获取触发OracleException的列
如果我从插入或更新语句返回 ORA-12899。如何从 OracleException 中提取列名而不解析字符串?
ORA-12899: 列“SCHEMA”.“TABLENAME”.“COLUMNNAME”的值太大(实际值:175,最大值:23)。
我想做这样的事情:
try
{
// Insert code.
}
catch (OracleException orclEx)
{
if (orclEx.Number == 12899)
{
string columnName = GetColumnName(orclEx);
throw new Exception(columnName + " value is too long.", orclEx);
}
}
finally
{
// Finally code
}
If I have ORA-12899 returned from an insert or update statement. How can I extract the column name from the OracleException without parsing the string?
ORA-12899: value too large for column "SCHEMA"."TABLENAME"."COLUMNNAME" (actual: 175, maximum: 23).
I would like to do something like this:
try
{
// Insert code.
}
catch (OracleException orclEx)
{
if (orclEx.Number == 12899)
{
string columnName = GetColumnName(orclEx);
throw new Exception(columnName + " value is too long.", orclEx);
}
}
finally
{
// Finally code
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道如何在不解析错误消息的情况下执行此操作。
我首先尝试防止不良数据进入数据库。
因此,在 ASP.NET 表单中,我使用这样的正则表达式验证器。
这可以防止您传递超过 100 个字符。
您可以输入超过 100 个字符,但是当您点击“确定”或“提交”按钮时,它不会处理数据,直到您缩短输入。
此外,我使用验证摘要来显示 ErrorMessage。
另外,我将值传递给存储过程并使用 PL/SQL 进行更新。
就解析错误信息来说,通过解析得到列名确实不会太难。
I don't know how to do this without parsing the error message.
I try to prevent bad data from getting to the database in the first place.
So, in an ASP.NET form I use a regular expression validator like this.
This one prevents you from passing more than 100 characters.
You can type in more than 100 characters, but when you hit the OK or Submit button, it will not process the data until you shorten the input.
In addition, I use a validation summary to display the ErrorMessage.
Also, I pass the values to a stored procedure and do the update using PL/SQL.
As far as parsing the error message, it really wouldn't be too difficult to get the column name by parsing.