Reputation: 21
I am trying to find the most popular rented car from given data and also the total days rented. I have written this PL/SQL code to do the job
create or replace procedure CarRentalSiteDetail (id IN CarRentalSite.CarRentalSiteId%TYPE) as
rental_name CarRentalSite.CarRentalSiteName%TYPE;
rental_city CarRentalSite.City%TYPE;
num number;
pop number;
c_name Car.CarName%TYPE;
total number;
BEGIN
Select CarRentalSite.CarRentalSiteName into rental_name from CarRentalSite where CarRentalSiteId = id;
Select CarRentalSite.City into rental_city from CarRentalSite where CarRentalSiteId = id;
Select count(Rentals.CarRentalSiteId) into num from CarRentalSite INNER JOIN Rentals ON CarRentalSite.CarRentalSiteId = Rentals.CarRentalSiteId where CarRentalSite.CarRentalSiteId = id Group by CarRentalSite.CarRentalSiteId;
Select CarId into pop from (Select CarId, count(count) as c from Rentals Group By CarId Order By c desc) where rownum = 1;
Select Car.CarName into c_name from Car where CarId = pop;
Select t into total from (Select CarId, sum(count) as t from Rentals Group By CarId) s where s.CarId = pop;
dbms_output.PUT_line(CONCAT('CarRentalSite Name: ',rental_name));
dbms_output.PUT_line(CONCAT('CarRentalSite City: ',rental_city));
dbms_output.PUT_line(CONCAT('CarRentalSite Total Rentals: ',num));
dbms_output.PUT_line(CONCAT('Most Popular Compact Car: ',c_name));
dbms_output.PUT_line(CONCAT('Total Days Rented: ', total));
END CarRentalSiteDetail;
/
show errors;
BEGIN
CarRentalSiteDetail(1);
end;
/
What I wrote logically makes sense to me and should do the job, but it returns this error I am having trouble fixing
15/1 PL/SQL: SQL Statement ignored
15/49 PL/SQL: ORA-00904: "COUNT": invalid identifier
17/1 PL/SQL: SQL Statement ignored
17/45 PL/SQL: ORA-00904: "COUNT": invalid identifier
Upvotes: 0
Views: 111
Reputation: 30645
count is a reserved word in Oracle DB (in most of the SQL servers), and you cannot use it as column or variable name.
Try changing it and you wont be getting this error
Upvotes: 2