【发布时间】:2022-01-01 12:58:09
【问题描述】:
在尝试查找距离旅行的最小值/最大值时,我收到错误“PLS-00302:必须声明组件'MIN'”。有什么想法吗?
create or replace procedure longandshortdist (p_distance in number)
is
cursor longshortcursor is
select source_town, destination_town, distance
from distances
where distance = p_distance;
distance_row longshortcursor%rowtype;
begin
for distance_row in longshortcursor
loop
dbms_output.put_line('source town is: ' || distance_row.source_town || 'destination
town is: ' || distance_row.destination_town || 'shortest trip is: ' ||
distance_row.min(distance) || 'longest trip is: ' || distance_row.max(distance));
end loop;
end;
我得到的错误代码:
12/1 PL/SQL: Statement ignored
12/169 PLS-00302: component 'MIN' must be declared
Errors: check compiler log
【问题讨论】:
-
你不能这样使用
MIN和MAX;它们是在 SQL 语句(而不是 PL/SQL)中工作的聚合函数,通常不会将它们应用于单行。请edit 使用minimal reproducible example 提出您的问题,包括为您的表添加CREATE TABLE语句;样本数据的INSERT语句;以及您的程序的预期输出,以便我们了解您想要实现的目标。 -
我认为您可能对这里的逻辑有些困惑。您的过程接受一个参数,然后在 where 子句中使用它:where distance = p_distance; 所以从该游标返回的每一行都将具有相同的距离。 MIN 和 MAX 在这方面是有意义的。