不允许在用户定义函数主体中内置不确定函数;这些不确定函数如下:@@CONNECTIONS @@TOTAL_ERRORS
@@CPU_BUSY @@TOTAL_READ
@@IDLE @@TOTAL_WRITE
@@IO_BUSY GETDATE ----------*getdate 在黑名单中
@@MAX_CONNECTIONS GETUTCDATE
@@PACK_RECEIVED NEWID
@@PACK_SENT RAND
@@PACKET_ERRORS TEXTPTR
@@TIMETICKS
@@CPU_BUSY @@TOTAL_READ
@@IDLE @@TOTAL_WRITE
@@IO_BUSY GETDATE ----------*getdate 在黑名单中
@@MAX_CONNECTIONS GETUTCDATE
@@PACK_RECEIVED NEWID
@@PACK_SENT RAND
@@PACKET_ERRORS TEXTPTR
@@TIMETICKS
create view v_getdate as select re=getdate()
go--在自定义函数中,就可以通过视图得到当前日期
create function f_test()
returns datetime
as
begin
declare @re datetime
select @re=re from v_getdate
return(@re)
end
--先建立一个视图
create view v_getdate
as
select getdate() as now
go--建立函数
create function fn_Getdate()
returns datetime
as
begin
return (select dateadd(day,1,now) from v_getdate)
end--调用示例
select dbo.fn_Getdate()--测试结果
/*
------------------------------------------------------
2004-08-26 17:18:53.937(所影响的行数为 1 行)*/