Thanks to Darren Sargent, we have what appears to be the first PL/SQL post. And that comes as quite a shock to me, considering all of the absurdly stupid things you can do with Oracle.

Q: How do you generate an 8-digit random number in PL/SQL?

A: Keep generating random numbers in an infinite loop until you get one that's 8 digits in length:

l_int_seed_value:=((SYSDATE - TO_DATE('01011970','mmddyyyy'))*24*3600);
dbms_random
.initialize(l_int_seed_value);

out_num_rand
:=dbms_random.random;

WHILE out_num_rand<0 OR (LENGTH(TO_CHAR(out_num_rand)) !=8
)
LOOP

  out_num_rand
:=dbms_random.random;

END LOOP;

If you answered “utilize the Range parameter of dbms_random,” please give your self a check-minus..

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!