Create View v_getdateasselect getdate () [output] Go -------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------- create function f_getdate () returns datetimeasbendeclare @n DateTimeSelect @n = Output from v_getdatereturn (@n) endgo -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- -------
Call: select dbo.f_getdate () =========================================== ============================ ----- The following is the analysis -------- should not allow for the inside of function Using a function can be determined or uncertain. If the result returned when the function is called with a set of specific input values, these functions are determined. If the function is used each time the function is used, the result is always different, and these functions are uncertain.
Uncertain functions generate side effects. Side effects are some global states of the database, such as updating database tables or certain external resources such as files or networks (eg, modifying files or email messages).
Do not allow for built-in uncertain functions 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 generate side effects when calling the extended stored procedure.
Since the expansion stored procedure generates side effects, the function of calling the extended stored procedure is uncertain. When the user-defined function call generates a side effects of the database, do not expect the result set to keep the consistent or execution function.