我在我的數據庫3個表:這個PL/SQL塊代碼有什麼問題?
manufacturer: IDm int primary key, manufacturerName varchar.
car: IDc int primary key, manufacturer foreign key references manufacturer(IDm).
rent: IDr int primary key, car foreign key references car(IDc).
我想創建一個打印出每個製造商的程序:被製造的汽車的數量製造商以及製造商製造的租賃車輛的數量。
這是我的代碼:
create or replace procedure Q8 as
cursor c is select distinct manufacturername, IDm from manufacturer;
cursor c2 is select * from car;
rents int:=0;
cars int;
allrents int;
p1 number(38,2);
p2 number(38, 2);
id int;
begin
select count(IDr) into allrents from rent;
dbms_output.put_line('manufacturer cars rented cars % rents %');
for k in c loop
select count(IDc) into cars from car c where c.manufacturer=k.IDm;
for k2 in c2 loop
select IDc into id from car where car.manufacturer=k.IDm;
select count(car) into rents from rent r where r.car=id;
end loop;
p1:=(rents/cars)*100;
p2:=(rents/allrents)*100;
dbms_output.put_line(k.manufacturerName||' '||cars||' '||p1||' '||p2);
end loop;
end;
所以,這裏是我的代碼錯了嗎?
你這是什麼是什麼意思?它是否運行,但給出錯誤的結果?你有錯誤信息嗎? – Sparky
@Sparky,是的,我得到了這個結果'ORA-01403:找不到數據。 –
那麼,錯誤信息不能更具體。您的「select into」語句之一是沒有返回任何數據。逐句通過調試器中的代碼,或打印出約束值。 – OldProgrammer