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

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

Upvotes: 0

Views: 815

Answers (2)

Bart van der Drift
Bart van der Drift

Reputation: 1336

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;

Upvotes: 0

Kombajn zbożowy
Kombajn zbożowy

Reputation: 10693

You don't need loops for this.

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

Upvotes: 2

Related Questions