Question For Practice Oracle (11g) With Answers
Question For Practice Oracle (11g) With Answers
Question For Practice Oracle (11g) With Answers
ASSESSMENT-01
Registration number-17BIT0308 Name-Kushagra Garg slot-L23+L24
:
Railway Reservation System -(Redesigning IRCTC database)
Train(train Number, name, source, destination,start_time, reach_time, traveltime, distance,
class,
days, type)
Ticket( PNRNo,Transactionid, from_station, To_station, date_of_journey, class
date_of_booking, total_ticket_fare,train number)
Passenger(PNR No, Serial no, Name, Age, Reservation_status)
Train_Route(Train_No, route_no, station_code, name, arrival_time, depart_time, distance,day)
Train_Ticket_fare(Train_No, class, base_fare, reservation_charge, superfast_charge,
other_charge, tatkal_charge, service_tax)
Q1) 1. Create all the tables specified above. Make underlined columns as primary key.(use number,
Insert atleast 5 rows to each table. (Check www.irctc.co.in website for actual data)
2 /
Type created.
2 /
Table created.
Table created.
Table created.
Table created.
a) Use Interactive insertion for inserting rows to the table.
2
&train_number,&name,&source,&destination,&start_time,&reach_time,&traveltime_hours,&distance_
km,&class,&days,&type);
old 2:
&train_number,&name,&source,&destination,&start_time,&reach_time,&traveltime_hours,&distance_
km,&class,&days,&type)
1 row created.
old 2:
&train_number,&name,&source,&destination,&start_time,&reach_time,&traveltime_hours,&distance_
km,&class,&days,&type)
1 row created.
2
&train_number,&name,&source,&destination,&start_time,&reach_time,&traveltime_hours,&distance_
km,&class,&days,&type);
old 2:
&train_number,&name,&source,&destination,&start_time,&reach_time,&traveltime_hours,&distance_
km,&class,&days,&type)
1 row created.
2
&train_number,&name,&source,&destination,&start_time,&reach_time,&traveltime_hours,&distance_
km,&class,&days,&type);
old 2:
&train_number,&name,&source,&destination,&start_time,&reach_time,&traveltime_hours,&distance_
km,&class,&days,&type)
1 row created.
2
&train_number,&name,&source,&destination,&start_time,&reach_time,&traveltime_hours,&distance_
km,&class,&days,&type);
old 2:
&train_number,&name,&source,&destination,&start_time,&reach_time,&traveltime_hours,&distance_
km,&class,&days,&type)
1 row created.
2
&PNRNO,&Transactionid,&from_station,&to_station,&date_of_journey,&class,&date_of_booking,&tota
l_ticket_fare,&train_number);
old 2:
&PNRNO,&Transactionid,&from_station,&to_station,&date_of_journey,&class,&date_of_booking,&tota
l_ticket_fare,&train_number)
2
&PNRNO,&Transactionid,&from_station,&to_station,&date_of_journey,&class,&date_of_booking,&tota
l_ticket_fare,&train_number);
old 2:
&PNRNO,&Transactionid,&from_station,&to_station,&date_of_journey,&class,&date_of_booking,&tota
l_ticket_fare,&train_number)
1 row created.
2
&PNRNO,&Transactionid,&from_station,&to_station,&date_of_journey,&class,&date_of_booking,&tota
l_ticket_fare,&train_number);
old 2:
&PNRNO,&Transactionid,&from_station,&to_station,&date_of_journey,&class,&date_of_booking,&tota
l_ticket_fare,&train_number)
1 row created.
2
&PNRNO,&Transactionid,&from_station,&to_station,&date_of_journey,&class,&date_of_booking,&tota
l_ticket_fare,&train_number);
1 row created.
2
&PNRNO,&Transactionid,&from_station,&to_station,&date_of_journey,&class,&date_of_booking,&tota
l_ticket_fare,&train_number);
old 2:
&PNRNO,&Transactionid,&from_station,&to_station,&date_of_journey,&class,&date_of_booking,&tota
l_ticket_fare,&train_number)
1 row created.
SQL> insert into Passenger_details VALUES(
2 &PNRNO,&serialno,&name,&Age,&reservation_status);
old 2: &PNRNO,&serialno,&name,&Age,&reservation_status)
1 row created.
2 &PNRNO,&serialno,&name,&Age,&reservation_status);
old 2: &PNRNO,&serialno,&name,&Age,&reservation_status)
1 row created.
old 2: &PNRNO,&serialno,&name,&Age,&reservation_status)
1 row created.
2 &PNRNO,&serialno,&name,&Age,&reservation_status);
old 2: &PNRNO,&serialno,&name,&Age,&reservation_status)
1 row created.
2 &PNRNO,&serialno,&name,&Age,&reservation_status);
Enter value for pnrno: 2334567892
old 2: &PNRNO,&serialno,&name,&Age,&reservation_status)
1 row created.
2 &Train_No,&route_no,&station_code,&name,&arrival_time,&depart_time,&distance,&day);
old 2: &Train_No,&route_no,&station_code,&name,&arrival_time,&depart_time,&distance,&day)
new 2: 12461,5,'JP','JAIPUR','02:35','02:45',308,2)
1 row created.
SQL> insert into Train_Route values(
2 &Train_No,&route_no,&station_code,&name,&arrival_time,&depart_time,&distance,&day);
old 2: &Train_No,&route_no,&station_code,&name,&arrival_time,&depart_time,&distance,&day)
1 row created.
2 &Train_No,&route_no,&station_code,&name,&arrival_time,&depart_time,&distance,&day);
old 2: &Train_No,&route_no,&station_code,&name,&arrival_time,&depart_time,&distance,&day)
new 2: 12461,5,'JP','JAIPUR','02:35','02:45',308,2)
1 row created.
2 &Train_No,&route_no,&station_code,&name,&arrival_time,&depart_time,&distance,&day);
old 2: &Train_No,&route_no,&station_code,&name,&arrival_time,&depart_time,&distance,&day)
1 row created.
2
&train_number,&class,&base_fare,&reservation_charge,&superfast_charge,&other_charge,&tatkal_cha
rge,&service_tax);
Enter value for train_number: 12050
old 2:
&train_number,&class,&base_fare,&reservation_charge,&superfast_charge,&other_charge,&tatkal_cha
rge,&service_tax)
1 row created.
2
&train_number,&class,&base_fare,&reservation_charge,&superfast_charge,&other_charge,&tatkal_cha
rge,&service_tax);
new 2: 12461,'sleeper',320,20,30,NULL,101,NULL)
1 row created.
SQL>
2
&train_number,&class,&base_fare,&reservation_charge,&superfast_charge,&other_charge,&tatkal_cha
rge,&service_tax);
old 2:
&train_number,&class,&base_fare,&reservation_charge,&superfast_charge,&other_charge,&tatkal_cha
rge,&service_tax)
new 2: 12616,'sleeper',730,20,30,NULL,230,NULL)
1 row created.
old 2:
&train_number,&class,&base_fare,&reservation_charge,&superfast_charge,&other_charge,&tatkal_cha
rge,&service_tax)
new 2: 12621,'sleeper',730,20,30,NULL,230,NULL)
1 row created.
2
&train_number,&class,&base_fare,&reservation_charge,&superfast_charge,&other_charge,&tatkal_cha
rge,&service_tax);
old 2:
&train_number,&class,&base_fare,&reservation_charge,&superfast_charge,&other_charge,&tatkal_cha
rge,&service_tax)
1 row created.
5 rows deleted.
Table renamed.
3. List all train details.
SQL>select *from Train;
TRAIN_NUMBER NAME SOURCE
------------ ------------------------------ ------------------------------
DESTINATION START_T REACH_T TRAVELTIME_HOURS DISTANCE_KM
------------------------------ ------- ------- ---------------- -----------
CLASS
--------------------------------------------------------------------------------
DAYS
--------------------------------------------------------------------------------
TYPE
------------------------------
12050 GATIMAAN EXPRESS H NIZAMUDDIN
AGRA CANTT 08:10 09:50 2 403
CLASS_TYPE('AC CHAIR CAR')
TRAIN_NUMBER NAME
------------ ------------------------------
12015 AJMER SHTBDI
12050 GATIMAAN EXPRESS
12461 MANDOR EXPRESS
12616 G T EXPRESS
12621 TAMIL NADU EXPRESS
6. List the senior citizen passengers details.
SQL> select *from Passenger_details where AGE>=60;
no rows selected
7. List the station names where code starts with 'M'.
SQL> select name from Train_Route where station_code='M*';
no rows selected
8. List the trains details within a range of numbers.
SQL> select *from Train where Train_number>=12000 and Train_number<=12500;
TRAIN_NUMBER NAME SOURCE
------------ ------------------------------ ------------------------------
DESTINATION START_T REACH_T TRAVELTIME_HOURS DISTANCE_KM
------------------------------ ------- ------- ---------------- -----------
CLASS
--------------------------------------------------------------------------------
DAYS
--------------------------------------------------------------------------------
TYPE
------------------------------
12050 GATIMAAN EXPRESS H NIZAMUDDIN
AGRA CANTT 08:10 09:50 2 403
CLASS_TYPE('AC CHAIR CAR')
9. Change the super fast charge value in train fare as zero , if it is null.
SQL> update Train_Ticket_fare set superfast_charge=0 where superfast_charge IS NULL;
0 rows updated.
10. List the passenger names whose tickets are not confirmed.
SQL> select *from Passenger_details where Reservation_status!='CONFIRM';
BASE_FARE
----------
582
462
Find the ticket details where transaction id is not known.
SQL> select *from Ticket where Transactionid='NULL';
no rows selected
1. Use Interactive updation for updating the serial no for particular PNR NO.
SQL> update Passenger_details set serialno=&serialno where pnrno=&pnrno;
Enter value for serialno: 6
Enter value for pnrno: 2334567850
old 1: update Passenger_details set serialno=&serialno where pnrno=&pnrno
new 1: update Passenger_details set serialno=6 where pnrno=2334567850
1 row updated.
2. Find the train names that are from Chennai to Mumbai, but do not have the source or
destination in its name.
SQL> select name from Train where SOURCE='CHENNAI' AND DESTINATION='MUMBAI'
AND NAME!='*CHENNAI*MUMBAI*' AND NAME!='*MUMBAI*CHENNAI*';
no rows selected
3 Find the train details that are on Thursday(Use the ADT column created).
3. Create (Alter table to add constraint) the necessary foreign keys by identifying the
relationships in the table. (Middle Level)
1. Add a suitable constraint to train table to always have train no in the range 10001 to
99999.
Table altered.
2. Add a suitable constraint for the column of station name, so that does not take
duplicates.
SQL> alter table Train_Route add constraint Train_Route_name_unique unique(name);
Table altered.
3. Change the data type of arrival time, depart time (date -> timestamp or timestamp to
date),
and do the necessary process for updating the table with new values.
SQL> alter table Train drop column start_time;
Table altered.
Table altered.
Table altered.
Table altered.
1 row updated.
SQL> update Train set start_time=to_timestamp('08-08-2018 06:05:00','dd-mm-yyyy
HH24:MI:SS'),reach_time=to_timestamp('08-08-2018 13:10:00','dd-mm-yyyy HH24:MI:SS')
where train_number=12015;
1 row updated.
1 row updated.
1 row updated.
1 row updated.
4. Add a suitable constraint for the class column that it should take values only as 1A, 2A,
3A, SL, C.
Class is of constraint varray
5. Add a not null constraint for the column distance in train_route.
Table altered.
no rows selected
2 Print the train names in upper case.
SQL> select upper(name) from Train;
UPPER(NAME)
------------------------------
GATIMAAN EXPRESS
TAMIL NADU EXPRESS
G T EXPRESS
AJMER SHTBDI
MANDOR EXPRESS
3 Print the passenger names with left padding character.
SQL> select lpad(name,20,'@') from Passenger_details;
LPAD(NAME,20,'@')
--------------------
@@@@@@@KUSHAGRA GARG
@@@@@@@@@KAMAL GUPTA
@@@@@@@@@MANUL GUPTA
@@@@@@@@@KAMAL GUPTA
@@@@@@@@AKSHAY GUPTA
4 Print the station codes replacing K with M.
SQL> select replace(station_code,'K','M') from Train_Route;
REPLACE(STATION_CODE
--------------------
JP
DEC
AGC
GWL
BPL
5. Translate all the LC in class column (Train_fare) to POT and display.
SQL> select translate(class,'LC','POT') from Train_ticket_fare;
TRANSLATE(CLASS,'LC','POT')
------------------------------
AO OHAIR OAR
AO OHAIR OAR
sleeper
sleeper
sleeper
6. Display the fare details of all trains, if any value is ZERO, print as NULL value.
SQL> select *from Train_Ticket_fare;
PNRNO NVL(TRANSACTIONID,'NOTGENERATE
---------- ------------------------------
2334567890 VADE0B248930
2334567880 VADE0B248920
2334567850 VADE0B248910
2334567892 VADE0B248910
2334567891 VADE0B248931
8. Print the date_of_journey in the format '27th November 2010'.
SQL> select to_char(to_date(date_of_journey,'DD/mm/yyyy'),'ddth month yyyy') from Ticket;
TO_CHAR(TO_DATE(DAT
-------------------
09th august 2018
10th august 2018
11th august 2018
06th august 2018
06th august 2018
9. Find the maximum fare (total fare).
SQL> select max(TOTAL_TICKET_FARE) from ticket;
MAX(TOTAL_TICKET_FARE)
----------------------
780
10. Find the average age of passengers in one ticket.
SQL> select avg(age) from Passenger_details;
AVG(AGE)
----------
22
11. Find the maximum length of station name available in the database.
SQL> select max(length(name)) from Train_route;
MAX(LENGTH(NAME))
-----------------
11
12. Print the fare amount of the passengers as rounded value.
SQL> select round(total_ticket_fare) from ticket;
ROUND(TOTAL_TICKET_FARE)
------------------------
700
665
370
780
780
13. Add the column halt time to train route.
SQL> alter table Train_route add Halt_time_min number(3);
Table altered.
14. Update values to it from arrival time and depart time.
SQL> update Train_route set Halt_time_min=10 where train_number=12461;
1 row updated.
1 row updated.
1 row updated.
1 row updated.
1 row updated.
High Level:
15. Update values to arrival time and depart time using conversion functions.
16. Display the arrival time, depart time in the format HH:MI (24 hours and minutes).
ARRIVAL_TI DEPART_TIM
---------- ----------
02:35 02:45
06:33 06:35
01:00 01:03
11:16 11:18
05:20 05:25