7) 1. Write A Simple PL/SQL Block To. 1. Print The Fibonacci Series
7) 1. Write A Simple PL/SQL Block To. 1. Print The Fibonacci Series
7) 1. Write A Simple PL/SQL Block To. 1. Print The Fibonacci Series
SQL> declare
2 a number(4):=1;
3 b number(4);
4 c number(4);
5 begin
6 b:=&b;
7 c:=b;
8 if b=0 or b=1 then
9 dbms_output.put_line(a);
10 end if;
11 loop
12 a:=b*a;
13 b:b-1;
14 exit when b=1;
15 end loop;
16 dbms_output.put_line('The factorial'||c||'is'||a);
17 end;
18 /
Enter value for b: 1
old 6: b:=&b;
new 6: b:=1;
PL/SQL procedure successfully completed.
3. Print 'NOT confirmed' based on the reservation status, of a particular passenger.
4. Print the total seats available for a particular train and for a particular class
SQL> declare
2 tno seats.train_no%type;
3 cls seats.class%type;
4 sts seats.total_seats%type;
5 begin
6 tno:=&tno;
7 cls:=&cls;
8 select total_seats into sts from seats where class=cls and train_no=tno;
9 dbms_output.put_line('The number of seats is'||sts);
10 end;
11 /
Enter value for tno: '12027'
old 6: tno:=&tno;
new 6: tno:='12027';
Enter value for cls: '1A','2A','3A','SL'
old 7: cls:=&cls;
new 7: cls:='1A','2A','3A','SL';
cls:='1A','2A','3A','SL';
PL/SQL procedure successfully completed.
SQL> declare
2 x ticket.train_number%type;
3 y ticket.date_of_journey%type;
4 cursor psngr_crs is select name,age from passenger_details natural join ticket where
train_number=x and date_of_journey=y;
5 begin
6 x:=&x;
7 y:=&y;
8 for psngr_rec in psngr_crs loop
9 dbms_output.put_line('The name &age of passenger_details is'||psngr_rec.name||' '||
psngr_rec.age);
10 end loop;
11 end;
12 /
Enter value for x: 12027
old 6: x:=&x;
new 6: x:=12027;
Enter value for y: 02-FEB-22
old 7: y:=&y;
new 7: y:=02-FEB-22;
Enter value for age: 18
SQL> declare
2 cursor train is
4 on train.train_number=ticket.train_number;
5 train_name train%rowtype;
6 begin
7 open train;
8 loop
11 dbms_output.put_line('Train name:'
12 || train_name.name || 'substation:'||train_name.from_station);
13 dbms_output.put_line(train_name.to_station);
14 dbms_output.put_line(train_name.source||','||train_name.destination);
15 end loop;
16 close train;
17 end;
18 /
OUTPUT:
Salem Junction
Nagpur
karur
Bngalore Cant
Madurai Junction
4.Write a cursor to update the reservation status of the passengers(generate seat number, if
seats have reached maximum, put waiting list number(30% of total seats), if waiting list
number reaches maximum, put PQWL(10%of total seats), RAC-20%)
8)
1. Write a PL/SQL procedure to.
1. List the details of passengers who has reserved next to “Mr. X”.
2. Get the Passenger name, train no and return the total journey time in hours and
minutes.
9)
Write a Trigger for the following:
1) When a passenger cancels a ticket, do the necessary process and update the cancellation
history table.
create or replace trigger tr_cnl_aft_del_dup after delete on ticket
for each row
declare
cursor psngr_crs is select * from ticket;
psngr_rec psngr_crs%rowtype;
psngr_pnr passenger.pnr_no%type;
begin
open psngr_crs;
loop
fetch psngr_crs into psnge_rec;
exit when psngr_crs%notfound;
if psngr_rec.pnr_no=:old.pnr_no then
psngr_pnr:=psngr_rec.pnr_no;
insert into ticket_psngr values
(:old.pnr_no,:old.transactionid,:old.from_station,:old.to_station,:old.date_of_journey,:o
ld.class,:old.date_of_book,:old.total_ticket_fare,:old.train_number,psngr_rec.serial_no,
psngr_rec.name,psngr_rec.age)
end if;
end loop;
close psngr_crs;
delete from psngr_dup where pnr_no=psngr_pnr;
end;
/
Trigger created.
Trigger created.
3)
create table fare_audit(
train_no char(5) not null,
last_update date,
new_fare number(10,2),
old_fare number(10,2),
primary key(train_no,last_update)
foreign key (train_no) references train);
Table created.
Trigger created.