Skip to content
Advertisement

Is there a shorter way to update a column with range values on Oracle SQL?

The update script will be like

So that when I run the query below

COLUMN_A has minimum value of 1 and maximum value of 10.

Advertisement

Answer

There is no “ranges” function in oracle, but you can emulate that using dbms_random which generates a value between 0 an 1. Multiply it by 10 so you get a value between 0 and 10 (10 will not be included). Round up (using CEIL function) so you get values 1 thru 10. Note that you will get random values between 1 and 10 in this example, there is no guarantee you have values 1 and 10 included and there will likely be duplicates.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement