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

三世轮回 提交于 2019-12-04 06:44:09

问题


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


回答1:


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:


You don't need loops for this.

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


来源:https://stackoverflow.com/questions/25250554/trying-to-create-a-list-of-values-including-a-table-value-and-numbers-below-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!