This is my attempt in creating a cursor in a stored procedure
--Second Stored Procedure--
CREATE OR REPLACE PROCEDURE sp_GetDiscountedRate (DiscountCode IN
This is what happens when you overcomplicate things, I'm afraid. I don't see any need for all those variables and the corresponding fetch into
that is hard to keep in sync. Why not just:
create or replace procedure sp_getdiscountedrate
( discountcode in varchar2
, percentage in number
, reservedate in date )
is
begin
for r in (
select p.passengerid
, p.first
, p.middle
, p.last
, p.passengertype
, u.usmilitaryid
, u.militarybranch
, u.militarydiscountcode
, r.flightnumber
, r.reservationcost
, r.reservationdate
, case u.militarydiscountcode
when discountcode then percentage * r.reservationcost
else r.reservationcost
end as revised_reservation_cost
from passenger p
join us_military u
on u.mpassengerid = p.passengerid
join reservation r
on r.passengerid = p.passengerid
and r.discountcode = u.militarydiscountcode
and r.reservedate = r.reservationdate
)
loop
dbms_output.put_line('CUSTOMER INFORMATION:');
dbms_output.put_line('The PassengerID is: ' || r.passengerid);
dbms_output.put_line('First Name of passenger is: ' || r.first);
dbms_output.put_line('Middle Name of passenger is: ' || r.middle);
dbms_output.put_line('Last Name of passenger is: ' || r.last);
dbms_output.put_line('Passenger Type of customer is: ' || r.passengertype);
dbms_output.put_line('US Military ID of Passenger is: ' || r.usmilitaryid);
dbms_output.put_line('Military Branch of passenger is: ' || r.militarybranch);
dbms_output.put_line('Military Discount code of passenger is: ' || r.militarydiscountcode);
dbms_output.put_line('Flight number of passenger is: ' || r.flightnumber);
dbms_output.put_line('Reservation Cost of passenger is: ' || r.reservationcost);
dbms_output.put_line('Reservation Date of passenger is: ' || r.reservationdate);
dbms_output.put_line('Revised reservation cost is: ' || r.revised_reservation_cost);
end loop;
end sp_getdiscountedrate;
(Untested)