Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

how to random select a value out of 2 letters

591556Oct 13 2007 — edited Oct 15 2007
I have have a column 'is_successful' of type char(1), I want to set it to either 'n' or 'y', cant get dbms_random working for this case, please help

Comments

Etbin

like this ?

select case when dbms_random.value(0,1) < 0.5 then 'y' else 'n' end is_successful from dual

or this ?

select translate(dbms_random.string('U',1),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','ynynynynynynynynynynynynyn') from dual

Regards

Etbin

Message was edited by: Etbin
user596003

Message was edited by:
user596003

MichaelS
or
select chr(121 - 11 * (round(dbms_random.value))) is_successful from dual
Aketi Jyuuzou
select distinct First_Value(is_successful) 
                over(order by dbms_random.value) as is_successful
from (select 'n' as is_successful from dual
      union all select 'y' from dual);

similar thread
569577

591556
thanks all, problem solved :)
121256
substr('yn', dbms_random.value(1,3), 1)
1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Nov 12 2007
Added on Oct 13 2007
5 comments
6,140 views