我有一个表有两列日期和费用。我想在plsql中使用循环概念在一个月内检索每日费用。有人可以说这是可能的吗?
答案 0 :(得分:0)
不知道你的桌子结构等我猜对了。 此外,这是在PL / SQL循环中执行此操作的一种非常基本的方式,如果您在程序中想要它或者在检索到数据后想要对数据执行什么操作,那么您还没有说过,所以我只是简单地说通过DBMS_OUTPUT输出。
此外,我使用了硬编码日期,因为您使用的日期信息也不完整。
如果您想要更具针对性的回复,您应该提出更具体的问题,我希望这可以帮助您解决问题。
BEGIN
FOR c_rec IN (SELECT expenses_date, -- Put actual column name in here
expenses_amount -- Put actual column name in here
FROM expenses -- Put actual table name in here
WHERE expenses_date BETWEEN TO_DATE('01-09-2015', 'DD-MM-YYYY')
AND TO_DATE('30-09-2015', 'DD-MM-YYYY')
LOOP
-- Do what you want here with the data you have retrieved in the loop
dbms_output.put_line('Date: '||c_rec.expenses_date||', Expenses: '||c_rec.expenses_amount);
END LOOP;
END;