检查数据库中的名称是否存在允许字符列表中的无效字符
CREATE PROCEDURE [dbo].[namecheck]
(@surname varchar(40))
AS
if @surname like '%[^0-9a-zA-Z .,?()\[\]:;''=/@$%*&!"-]%' ESCAPE '\' COLLATE Latin1_General_100_CS_AS
RETURN 1
RETURN 2
GO
DECLARE @returncode int
EXECUTE @returncode = namecheck 'Bum'
SELECT @returncode AS returncode
EXECUTE @returncode = namecheck 'Bumë'
SELECT @returncode AS returncode
GO
无论字符串的有效性如何,返回代码都是相同的,例如“Bum”应为返回代码 2,“Bumë”应为返回代码 1
CREATE PROCEDURE [dbo].[namecheck]
(@surname varchar(40))
AS
if @surname like '%[^0-9a-zA-Z .,?()\[\]:;''=/@$%*&!"-]%' ESCAPE '\' COLLATE Latin1_General_100_CS_AS
RETURN 1
RETURN 2
GO
DECLARE @returncode int
EXECUTE @returncode = namecheck 'Bum'
SELECT @returncode AS returncode
EXECUTE @returncode = namecheck 'Bumë'
SELECT @returncode AS returncode
GO
the return code is the same regardless of the validity of the string eg 'Bum' should be returncode 2 and 'Bumë' should be return code 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该检查是否存在任何非白名单字符:
You should check for the presence of any non whitelisted characters:
比如:
可以帮助你...
Something like :
May help you...