Heim  >  Artikel  >  Backend-Entwicklung  >  sql server关于函数中如何使用Getdate()_PHP教程

sql server关于函数中如何使用Getdate()_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:03:421115Durchsuche

create view v_getdate
as
select getdate() [output]
go
---------------------------------------------------------------
create function f_getdate()
returns datetime
as
begin
declare @n datetime
select @n = output from v_getdate
return(@n)
end
go
---------------------------------------------------------------
调用:select dbo.f_getdate()
======================================================================
-----以下是解析--------
应为function内部不允许使用
函数可以是确定的或不确定的。如果任何时候用一组特定的输入值调用函数时返回的结果总是相同的,则这些函数为确定的。如果每次调用函数时即使用的是相同的一组特定输入值,返回的结果总是不同的,则这些函数为不确定的。
不确定的函数会产生副作用。副作用是更改数据库的某些全局状态,比如更新数据库表或某些外部资源,如文件或网络等(例如,修改文件或发送电子邮件消息)。
不允许在用户定义函数主体中内置不确定函数;这些不确定函数如下:
@@CONNECTIONS @@TOTAL_ERRORS
@@CPU_BUSY @@TOTAL_READ
@@IDLE @@TOTAL_WRITE
@@IO_BUSY GETDATE
@@MAX_CONNECTIONS GETUTCDATE
@@PACK_RECEIVED NEWID
@@PACK_SENT RAND
@@PACKET_ERRORS TEXTPTR
@@TIMETICKS
尽管在用户定义函数主体中不允许有不确定函数,这些用户定义函数在调用扩展存储过程时仍会产生副作用。
由于扩展存储过程会对数据库产生副作用,因此调用扩展存储过程的函数是不确定的。当用户定义函数调用会对数据库产生副作用的扩展存储过程时,不要指望结果集保持一致或执行函数。
 


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/630947.htmlTechArticlecreate view v_getdate as select getdate() [output] go --------------------------------------------------------------- create function f_getdate() returns datetime as begin declare @...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn