Trying to create a "List of Values " including a table value and numbers below it

821 Views Asked by At

So basically say I have a table called "Device" and then one of the columns is "Quantity," what if I wanted to create a list of values that takes that number, say the quantity is 4, and the values are (quantity - 1) until !> 0, so in this case (4, 3, 2, 1)

I am using Oracle APEX and am assuming I need a dynamic LOV based on a sql query, but not sure how to get this. I've never used a for loop with PL/SQL

Thanks

2

There are 2 best solutions below

1
On BEST ANSWER

This should do it. Make sure that where I've put /* xxx */ you include a where clause that comes up with only 1 record. Most likely, you will use the ID of the Device table here.

SELECT     ROWNUM display_value
,          ROWNUM return_value
FROM       DUAL
CONNECT BY ROWNUM <= (SELECT Quantity FROM Device WHERE /* xxx */)
ORDER BY   ROWNUM DESC;
2
On

You don't need loops for this.

select level
from dual
connect by level <= 4
order by level desc;