1
可能重複:
Creating Nondeterministic functions in SQL Server using RAND()在函數中調用RAND()
我需要生成函數中的一些隨機nvarchar的。所以我創建這個函數:
CREATE FUNCTION [dbo].[sfp_GenerateRandomString]
(@length int) -- Length of string
RETURNS NVARCHAR
AS
BEGIN
DECLARE @random NVARCHAR(25) = ''
while @length > 0
begin
set @random = @random + nchar((cast(rand()*1000 as int)%26)+97)
set @length = @length-1
end
return @random
END
但因爲RAND()函數中誰得是確定SQL函數禁止這是行不通的。而蘭德()是非確定性的。
所以我的問題是如何在這種情況下生成隨機數? 謝謝。
謝謝,我需要一個SQL函數,因爲它不依賴於應用程序。數據混淆腳本允許共享數據庫 – bAN