在PL / SQL中生成随机字符串(oracle 12c)

时间:2019-04-09 18:13:06

标签: oracle plsql oracle12c

我正在尝试使用仅带2个固定字的PL / SQL生成随机字符串。有可能吗?

1 个答案:

答案 0 :(得分:1)

这是您要找的吗?

SQL> with
  2  -- two fixed words
  3  test as
  4    (select 'fixed words' col from dual),
  5  -- split them to rows
  6  inter as
  7    (select level lvl, regexp_substr(col, '.', 1, level) let
  8     from test
  9     connect by level <= length(col)
 10    )
 11  -- aggregate them back, randomly
 12  select listagg(let, '') within group (order by dbms_random.value(1, max_lvl)) result
 13  from inter
 14  join (select max(lvl) max_lvl from inter) on 1 = 1;

RESULT
--------------------------------------------------------------------------------
reiosdwxf d

SQL> /

RESULT
--------------------------------------------------------------------------------
fe ixoddrws

SQL> /

RESULT
--------------------------------------------------------------------------------
 wdxeorsdfi

SQL>