【发布时间】:2020-07-04 23:05:56
【问题描述】:
现在我创建了一个程序,我需要输入一个日期参数,该参数应该输出正确的attr 和给定的price。如果日期不存在,则应选择最新日期。
to_date('01-jan-19') 的解决方案表如下所示:
这将是过程中的输出行。
我应该选择更正元组并输出行,还是最好只批量收集所有内容,然后使用 if 语句检查 for 循环我需要显示什么元组。
到目前为止我所拥有的:
带有我要查找的元组的 select 语句:
create or replace procedure print_inf_value(closingDate Date) is
cursor d1 (closingDate Date) is
select t.attr, t.dateOfValue, t.price
from (
select i.*,
row_number() over (
partition by attr
order by case when dateOfValue = closingdate then 1 else 2 end, dateOfValue desc
) rn
from InformationValues i
) t
where t.rn = 1;
BEGIN
dbms_output.put_line('Information Value ');
dbms_output.put_line('--------------------------------');
FOR d1_rec IN d1 LOOP
dbms_output.put_line(d1_rec.attr || ' ' || d1_rec.price );
END LOOP;
END;
或者我批量收集所有内容然后我需要整理出我需要的元组的过程:
create or replace procedure print_inf_value(closingDate Date) is
TYPE d1 IS TABLE OF informationvalues%rowtype;
emps d1;
begin select * bulk collect into emps
from informationvalues;
FOR i IN 1 .. emps.COUNT LOOP
if emps(i).dateofvalue = closingDate then
dbms_output.put_line(emps(i).attr || ' ' || emps(i).price );
/*else*/
end if;
END LOOP;
END;
两者都不能正常工作,所以我缺少什么来显示具有正确日期的元组。
【问题讨论】: