Posted By

geekzspot on 12/01/12


Tagged


Versions (?)

Oracle random word from a list


 / Published in: SQL
 

To produce a random word or string or phrase from a specific list of words, strings, or phrases (for example 'foo', 'bar' or 'baz').

If you want to add NULL's into the possibilities, make the "number of strings" (in this example, 3) a higher number that there are strings. The higher the number, the more NULL's will be produced.

  1. SELECT REGEXP_SUBSTR('foo, bar, baz','([^,]+)',1,ROUND(DBMS_RANDOM.VALUE(1,3))) FROM DUAL; -- Where 3 is the number of words.

Report this snippet  

You need to login to post a comment.