Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate random hex color values in Oracle sql database

I'm aware similar questions have been asked, but I can't seem to find something that works. I'm creating a table in oracle database which one column is an ID and the other column's value is a hexadecimal color value. When I created the table I put the datatype for the ID as a number and VARCHAR2 for the color. I just want to know if there is a way to generate random hex color values and update the table so that they can be in the color column. Thanks.

like image 529
Anika Avatar asked Nov 18 '25 07:11

Anika


2 Answers

SELECT TO_CHAR( TRUNC( DBMS_RANDOM.VALUE( 0, 256*256*256 ) ), 'FM0XXXXX' )
FROM DUAL;
like image 79
MT0 Avatar answered Nov 20 '25 11:11

MT0


this should give you a pattern how to do it

select 1, to_char(floor(dbms_random.value(0,256)), 'XX') from dual
like image 23
vav Avatar answered Nov 20 '25 09:11

vav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!