Hi i executed the following stored procedure in .net web application. Then run the application. I got this error
您好我在.net Web应用程序中执行了以下存储过程。然后运行该应用程序。我收到了这个错误
" Divide By zero error "
“除以零错误”
Stored procedure:
CREATE procedure Details(@Stringtext varchar(8000),@SearchStringtext varchar(100))
as begin
SELECT ({fn LENGTH(@Stringtext)}-
{fn LENGTH({fn REPLACE(@Stringtext, @SearchStringtext, '')})})/
{ fn LENGTH(@SearchStringtext)}AS String_Count
end
6 个解决方案
#1
Evidently:
{ fn LENGTH(@SearchStringtext)}
... is evaluating to zero.
...正在评估为零。
#2
The length of the SearchStringText is Zero and hence there is divide by zero error. Make sure that when the function is called, the string is of non-zero length. Alternatively check for length before doing the select
SearchStringText的长度为零,因此有零除错误。确保在调用函数时,字符串的长度不为零。或者在选择之前检查长度
#3
{ fn LENGTH(@SearchStringtext)}
is evaluating to 0.
正在评估为0。
However, why is this a stored procedure? You are not using any db feature? Unless this is a simplified problem , all this (length, replace etc) could be done in your .net application
但是,为什么这是一个存储过程?您没有使用任何数据库功能?除非这是一个简化的问题,所有这些(长度,替换等)都可以在您的.net应用程序中完成
#4
If SearchStringtext is empty, the length of it becomes 0. Thus the stored procedure tries to divide by zero (which is an undefined thing to do).
如果SearchStringtext为空,则它的长度变为0.因此存储过程尝试除以零(这是一个未定义的事情)。
In other words the following part becomes zero:
换句话说,以下部分变为零:
{ fn LENGTH(@SearchStringtext)}
You might want to add some logic (if statement perhaps) to prevent the division to happen if the SearchStringtext is empty.
您可能希望添加一些逻辑(可能是if语句),以防止在SearchStringtext为空时发生除法。
#5
The only division operation in this procedure, has fn LENGTH(@SearchStringtext)
as the divisor.
此过程中唯一的除法运算,有fn LENGTH(@ SearchStringtext)作为除数。
Hence it seems that length of **SearchStringtext**
is evaluating to zero. It might be possible that you are trying to search an Empty string.
因此,似乎** SearchStringtext **的长度评估为零。您可能正在尝试搜索空字符串。
Please check and then elaborate the question details, along with the DB platform.
请检查并详细说明问题详细信息以及数据库平台。
#6
It seems that the length of SearchStringtext is 0 -- so the procedure tries to divide by zero.
看起来SearchStringtext的长度是0 - 所以过程试图除以零。
#1
Evidently:
{ fn LENGTH(@SearchStringtext)}
... is evaluating to zero.
...正在评估为零。
#2
The length of the SearchStringText is Zero and hence there is divide by zero error. Make sure that when the function is called, the string is of non-zero length. Alternatively check for length before doing the select
SearchStringText的长度为零,因此有零除错误。确保在调用函数时,字符串的长度不为零。或者在选择之前检查长度
#3
{ fn LENGTH(@SearchStringtext)}
is evaluating to 0.
正在评估为0。
However, why is this a stored procedure? You are not using any db feature? Unless this is a simplified problem , all this (length, replace etc) could be done in your .net application
但是,为什么这是一个存储过程?您没有使用任何数据库功能?除非这是一个简化的问题,所有这些(长度,替换等)都可以在您的.net应用程序中完成
#4
If SearchStringtext is empty, the length of it becomes 0. Thus the stored procedure tries to divide by zero (which is an undefined thing to do).
如果SearchStringtext为空,则它的长度变为0.因此存储过程尝试除以零(这是一个未定义的事情)。
In other words the following part becomes zero:
换句话说,以下部分变为零:
{ fn LENGTH(@SearchStringtext)}
You might want to add some logic (if statement perhaps) to prevent the division to happen if the SearchStringtext is empty.
您可能希望添加一些逻辑(可能是if语句),以防止在SearchStringtext为空时发生除法。
#5
The only division operation in this procedure, has fn LENGTH(@SearchStringtext)
as the divisor.
此过程中唯一的除法运算,有fn LENGTH(@ SearchStringtext)作为除数。
Hence it seems that length of **SearchStringtext**
is evaluating to zero. It might be possible that you are trying to search an Empty string.
因此,似乎** SearchStringtext **的长度评估为零。您可能正在尝试搜索空字符串。
Please check and then elaborate the question details, along with the DB platform.
请检查并详细说明问题详细信息以及数据库平台。
#6
It seems that the length of SearchStringtext is 0 -- so the procedure tries to divide by zero.
看起来SearchStringtext的长度是0 - 所以过程试图除以零。