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
---------------------------------------------------------------
Call: select dbo. f_getdate ()
========================================================== ====================================
----- The following is the resolution --------
The function cannot be used internally.
The function can be definite or uncertain. If the returned results are always the same when a function is called with a specific set of input values, these functions are definite. If the same set of specific input values are used for each function call and the returned results are always different, these functions are uncertain.
Uncertain functions produce side effects. The side effect is to change the global status of the database, such as updating the database table or some external resources, such as files or networks (such as modifying files or sending email messages ).
Built-in uncertain functions are not allowed in the user-defined function body. These uncertain functions are as follows:
@ 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
Although uncertain functions are not allowed in the user-defined function body, these user-defined functions still produce side effects when calling the extended stored procedure.
Because the extended stored procedure has a side effect on the database, it is uncertain to call the extended stored procedure function. When you define a function call to extend the stored procedure that has Database side effects, do not expect the result set to be consistent or execute the function.