SQL:插入之前的插入操作中的数据大小
这听起来像是一个琐碎的问题,但我找不到任何直接的答案。
基本上,我有一个接受某些参数的SQL存储过程。参数将被处理以生成值,该值将在存储过程中以后在插入操作中使用。
现在,根据异常案例,传递的值可能会导致某些插入操作包含列的最大长度的值。我想捕捉这些方案,如果肯定会失败,则不要经历插入操作。
此外,如果确实发生了这种情况,我希望存储的过程以某种方式终止,以便调用模块知道它没有成功,类似于以多种语言进行异常处理中使用的类似。
更新:我知道我可以使用try/catch,但是它将在 Insights 中记录错误,并且我想防止此错误。
This sounds like a trivial problem and it probably is, but I couldn't find any straightforward answer anywhere.
Basically, I have a SQL stored procedure accepting some parameters. The parameters will be processed to generate values which will be used in an insert operation later on in the stored procedure.
Now, depending on exceptional cases, the passed values may result in some insert operations to contain values exceeding max length for a column. I would like to catch those scenarios and not go through the insert operation if it's certain to fail.
Additionally, if such a scenario does occur, I want the stored procedure to terminate in a manner so the calling module knows it didn't succeed, analogical to THROW as used in exception handling in many languages.
Update: I know I can use Try/Catch but it will log error in the insights and I want to prevent this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,您将需要在Sproc中使用尝试捕获块以进行错误处理。
然后能够判断值是否会超过数据类型长度,以获取列的最大数据长度。您可以使用以下(如果有许可)来获得此功能,
最后您只需要获得变量的长度即可。您可以像下面一样做到这一点
,然后您只需要将其放在一起
So you'll want to use a try catch block in your sproc for error handling.
Then to be able to tell whether or not a value will exceed the data type length you will need to get the maximum data length of your column. You can get this using below (if you have permission)
Lastly you will just need to get the length of your variable. You can do that like below
Then you just need to put it together