oracle生成随机字符串
前言
记录一下在Oracle中用年月日时分秒拼随机字符串生成主键的一种操作
----dbms_random.string (opt char, len number);
--opt:表示返回值可能包含的东西
--len:表示要返回的字符串长度
----'u','U' : 任何大写字母
----'l','L' : 任何小写字母
----'a','A' : 大小写混合字母
----'x','X' : 大写字母和数字混合
----'p','P' : 任何可打印字符
----其他参数 : 任何大写字母
dbms_random.value(1,100): --生成1-100之间的随机小数,取值范围[1,100)
--------trunc截取数值,默认取整数,
---------生成1-1000之间的整数
select trunc(dbms_random.value(1,1000)) from dual;
--------随机生成6位大写字母的字符串
select dbms_random.string('u', 6) from dual;
--------随机生成6位小写字母的字符串
select dbms_random.string('l', 6) from dual;
--------随机生成6位大小写混合字母的字符串
select dbms_random.string('a', 6) from dual;
--------随机生成6位大写字母和数字混合的字符串
select dbms_random.string('x', 6) from dual;
--------随机生成6位可打印字符的字符串
select dbms_random.string('p', 6) from dual;
--------年月日时分秒拼接6位大小写混合的字母,
select to_char(SYSDATE,'yyyyMMddhh24miss')||dbms_random.string('a', 6) from dual;
--------年月日时分秒拼接6位大写字母和数字混合的字符串
select to_char(SYSDATE,'yyyyMMddhh24miss')||dbms_random.string('x', 6) from dual;
--------年月日时分秒拼接6位大小写混合的字母,再拼接6位大写字母和数字混合的字符串
select to_char(SYSDATE,'yyyyMMddhh24miss')||dbms_random.string('a', 6)||dbms_random.string('x', 6) from dual;
创作不易,如果这篇文章能够帮助到你,希望能关注或收藏一下笔者,如果文章内容有问题还望指正,共同学习,进步!