sqlserver函数(function)中不能使用临时表
发布时间:2020-12-12 12:58:34 所属栏目:MsSql教程 来源:网络整理
导读:比如有,如下function CREATE FUNCTION dbo.functionName( @id INT,@type VARCHAR(20)) RETURNS TABLEASBEGINCREATE TABLE #Temporary_table_name(t_idINT NOT NULL)END 这样写完,run之后会抱错的:Cannot access temporary tables from within a function.
比如有,如下function CREATE FUNCTION dbo.functionName( @id INT,@type VARCHAR(20) ) RETURNS TABLE AS BEGIN CREATE TABLE #Temporary_table_name ( t_id INT NOT NULL ) END 这样写完,run之后会抱错的:Cannot access temporary tables from within a function. 或许sqlserver db就是这样设计的,让我们如果遇到复杂的逻辑,需要使用临时表的时候,去使用存储过程写。 有简单的逻辑,避免使用临时表,去用函数实现。 参考url:http://stackoverflow.com/questions/9561626/cannot-access-temporary-tables-from-within-a-function (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |