随机生成编码(判断重复)(oracle函数)
create or replace function generate_coupons_code(v_length in number:=16) return varchar2 is
v_code varchar2(70);
type t_arr is varray(16) of varchar2(1);
char_arr t_arr;
flag number(1,0):= 0;
begin
char_arr:=t_arr('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
for i in 1..v_length
loop
v_code:=v_code||char_arr(floor(dbms_random.value(1,17)));
--dbms_output.put_line(floor(dbms_random.value(1,17)));
end loop;
select count(1) into flag from b_coupons c WHERE c.code = v_code;
if flag > 0 then
return generate_coupons_code(v_length);
end if;
return(v_code);
end generate_coupons_code;
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。