内联函数与普通函数 select
Inline function versus normal select
现在正在研究SQLServer 2012中的函数。我知道函数类型分为三种。但是我对Inline Table-Value Functions
感到困惑。
让我解释一下。
select * into Number
from (
values
(1, 'A'),(2, 'B'),(3, 'C')
) number (N, C)
create function InlineFun (@i int)
returns table
as
return (select * from Number where n = @i)
select * from Number where n = 1
select * from InlineFun (1)
与上面select
的结果是一样的。那么Inline TVF
..?
的具体范围是什么
注:
我正在使用 Microsoft SQL Server 2012
将 ITVF
视为可以向其传递参数的 view
。它基本上包含在您的脚本中,就像它是普通的旧 SQL 一样引用它然后执行。这就是为什么它们比多语句 table 值函数执行得更好,后者必须作为单独的语句执行。
因此,在您的示例中声明:
select *
from InlineFun (1)
本质上传递给查询引擎为:
select *
from (select *
from Number
where n = 1
) as a
所以要真正回答你的问题,函数的范围与调用它的语句的范围相同。
现在正在研究SQLServer 2012中的函数。我知道函数类型分为三种。但是我对Inline Table-Value Functions
感到困惑。
让我解释一下。
select * into Number
from (
values
(1, 'A'),(2, 'B'),(3, 'C')
) number (N, C)
create function InlineFun (@i int)
returns table
as
return (select * from Number where n = @i)
select * from Number where n = 1
select * from InlineFun (1)
与上面select
的结果是一样的。那么Inline TVF
..?
注:
我正在使用 Microsoft SQL Server 2012
将 ITVF
视为可以向其传递参数的 view
。它基本上包含在您的脚本中,就像它是普通的旧 SQL 一样引用它然后执行。这就是为什么它们比多语句 table 值函数执行得更好,后者必须作为单独的语句执行。
因此,在您的示例中声明:
select *
from InlineFun (1)
本质上传递给查询引擎为:
select *
from (select *
from Number
where n = 1
) as a
所以要真正回答你的问题,函数的范围与调用它的语句的范围相同。