oracle - 它不工作。任何人都可以帮我解决它吗?
问题描述
我创建了这个程序,但它说“PLS-00364:循环索引变量'DS'使用无效”和“ORA-00942:表或视图不存在”。我该如何解决?
create or replace procedure thangmax3(
nam IN number)
as
begin
nam:=&nam;
dbms_output.put_line('DS 3 thang nhieu khach den o ksan nhat nam '||nam);
for ds in (select d.thang, d.sokhach from (select extract(month from thoigiannhan)as thang,COUNT(mathuephong)sokhach from HR.thong_tin_thue_phong
where extract(year from thoigiantra)=nam
group by extract(month from thoigiannhan)
order by COUNT(mathuephong) DESC) d
where rownum<=3)
loop
dbms_output.put_line('Thang: '||ds.thang||' '||'So khach: '||ds.soluong);
end loop;
end;
解决方案
那么只有代码中涉及的“真实”表是
hr.thong_tin_thue_phong
由于您在其名称前加上所有者名称 ( hr
),我猜您当前未连接为hr
. 如果是这样,hr
应授予select
您特权以使此查询起作用。
所以:连接hr
并运行
grant select on thong_tin_thue_phong to user_that_runs_that_pl/sql_block;
至于你得到的另一个错误:在dbms_output.put_line
循环内的调用中,你正在引用,但是 - 它在循环的查询ds.soluong
中不存在:它有,所以 - 使用它们。FOR
thang
sokhach
此外,如果您创建了一个带IN
参数的过程,则不会使用替换变量来请求它。程序是:
create or replace procedure thangmax3(par_nam IN number)
as
begin
dbms_output.put_line('DS 3 thang nhieu khach den o ksan nhat nam '|| par_nam);
for ds in (select d.thang,
d.sokhach
from (select extract (month from thoigiannhan) as thang,
COUNT(mathuephong) sokhach
from HR.thong_tin_thue_phong
where extract (year from thoigiantra) = par_nam
group by extract (month from thoigiannhan)
order by COUNT(mathuephong) DESC
) d
where rownum<=3
)
loop
dbms_output.put_line('Thang: '||ds.thang||' '||'So khach: '||ds.sokhach);
end loop;
end;
你可以称之为
begin
thangmax3(&nam);
end;
/
推荐阅读
- angular - “AngularFireObject”类型上不存在属性“take”
'.ts - c# - C# 将 XML 反序列化为模型类错误 -
没有预期 - unity3d - XR 设备 (Oculus) 在 Unity 的新输入系统中启动未配对
- javascript - Webpacker 找不到 application.js
- javascript - 从按钮列表中创建 Javascript 中的随机按钮
- java - 如何使用 SpringBoot + JPA 在 POSTGRES 中存储 JSON?
- java - 数据没有从 Firebase 读入我的 ArrayList
- python-3.x - 我必须在一行中每 3 个元素之后打印一个带有空格的网格,每三行之后打印一个空行,但我无法弄清楚代码
- c# - Brother Bpac SDK - .NET 核心和 .NET 5 的访问冲突,但不是 .NET 框架
- php - WooCommerce 根据特定产品的购买数量收取额外费用