I have 3 tables in my db:
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).
I want to create a procedure that prints out for each manufacturer : the number of cars that are made the manufacturer, and the number of the rented cars that are made by the manufacturer.
this is my code:
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;
so, where is the wrong in my code?
ORA-01403: no data found.select IDc into id from car where car.manufacturer=k.IDm;, but it should return data.SELECTstatement fails? Perhaps you could put something likeDBMS_OUTPUT.PUT_LINE('k.IDm=' || k.IDm);right before the failingSELECTstatement.