SQL 十位隨機數(大小寫字母 資料)

2022-03-22 10:53:45 字數 1639 閱讀 5320

use [test]

go/****** object: userdefinedfunction [dbo].[randtennums] script date: 2019/7/23 15:40:16 ******/

set ansi_nulls on

goset quoted_identifier on

gocreate function [dbo].[randtennums]()

returns varchar(10)

asbegin

declare @i int

declare @flag int

declare @serialnumber nvarchar(20)

declare @rands numeric(38,38)

--初始化設定

set @i=1

set @serialnumber = ''

--生成10位隨機碼

while @i<11

begin

--設定隨機,這個隨機會選擇字母(大小寫)還是數字

select @rands = rand_a from [dbo].[vw_rand]

set @flag=ceiling(@rands *3)

if @flag=1

begin

--隨機字母(大寫去除大寫的o)

select @rands = rand_a from [dbo].[vw_rand]

while char(65+ceiling(@rands * 25)) = 'o'

begin

select @rands = rand_a from [dbo].[vw_rand]

endselect @serialnumber=@serialnumber+char(65+ceiling(@rands * 25))

endelse if @flag=2

begin

--隨機字母(小寫去除小寫的o)

select @rands = rand_a from [dbo].[vw_rand]

while char(97+ceiling(@rands * 25)) = 'o'

begin

select @rands = rand_a from [dbo].[vw_rand]

endselect @serialnumber=@serialnumber+char(97+ceiling(@rands * 25))

endelse begin

--隨機數字 1至9的隨機數字(整數)

while cast(ceiling(@rands * 9) as varchar(1)) = '0'

begin

select @rands = rand_a from [dbo].[vw_rand]

endselect @rands = rand_a from [dbo].[vw_rand]

select @serialnumber=@serialnumber+cast(ceiling(@rands * 9) as varchar(1))

end--進行下乙個迴圈

set @i=@i+1

endreturn @serialnumber;

end

任意數字大小寫字母的隨機數的產生

vb.net版 private shared constant aschar public shared function generaterandom function generaterandom byval length asinteger as string dimnewrandom ass...

任意數字大小寫字母的隨機數的產生

vb.net版 private shared constant aschar public shared function generaterandom function generaterandom byval length asinteger as string dimnewrandom ass...

Random的生成隨機數小寫字母 數字

生成隨機數字和字母,public static string getstringrandom int length if isnum 6 輸出字母還是數字 if char equalsignorecase charornum else if num equalsignorecase charornu...