我从函数中得到这个错误:
- CREATE FUNCTION getLavel(@id int,@lavel char)
- RETURNS date
- BEGIN
- DECLARE @date date
- select @date = (select authorization_date from Authorized WHERE diver_number = @id and @lavel =level_name)
- return @date
- END
- GO
可能是什么原因?
非常.
解决方法
将其转换为内联表值函数.这将比标量函数表现更好.此外,您不应使用字符数据类型的默认大小.你知道char的默认长度是多少吗?你知道它可以根据使用情况而有所不同吗?
- CREATE FUNCTION getLavel
- (
- @id int,@lavel char --You need to define the length instead of the default length
- )
- RETURNS table
- return
- select authorization_date
- from Authorized
- WHERE diver_number = @id
- and @lavel = level_name
- GO