🦆 Oracle Database— Query Random Record

Ido Montekyo
idomongo
Published in
May 16, 2022

--

Photo by Jess Bailey on Unsplash

I have an Oracle database table with 101 Monday Motivation Quotes and I would like my app to randomly pick and display a quote on the homepage.

What is the easiest way to select a random record from an Oracle database table?

The following will result in one random record:

SELECT q.text FROM quotes q ORDER BY DBMS_RANDOM.value FETCH NEXT 1 ROWS ONLY;
TEXT                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
-----
"Start where you are. Use what you have. Do what you can." - Arthur Ashe

The quotes can be found on the positivity blog

“A ship is always safe at shore but that is not what it’s built for.”
– Albert Einstein

🍕

--

--

Ido Montekyo
idomongo

System Analysis. System Design. Architecture. Databases. Project Management. Speaker. People Motivator.