You are on page 1of 7

Expt 3: To implement Single row commands ( Date, Numeric , and Character )

Dop:18/1/16
Dos:1/2/16

1.Insert into fleet_header the following values


Attribute
Flight_Id
Date_of_Issue
Date_of_Travel
Time
Passenger_Name
Source

Datatype
Varchar2
Date
Date
Varchar2
Varchar2

Size
10
12
20

2. Insert into the Ticket header the following values:


Fligh
t_id
01

Doi

Dot

01-apr-96

02

12-apr-96

03

21-apr-96

04

25-apr-96

05

30-apr-96

10-may96
05-may96
15-may96
25-may96
22-may96

Time_
Travel
15:00:0
0
09:00:0
0
21:00:0
0
10:00:0
0
15:00:0
0

Passenger_
Name
Mahesh

Origin
Madras

Destination Total
fare
Madhurai
60

Reema

Madhurai

Madras

60

Aaliya

Bangalore

Madras

400

Raju

Hyderabad Madras

500

Ramya

Madras

141

Cochin

SQL> insert into ticket values('01','01-apr-96','10-may'96','15:00:00','Mahesh',


'Madras','Madurai',60)
2 ;
ERROR:
ORA-01756: quoted string not properly terminated
SQL> insert into ticket values('01','01-apr-96','10-may-96','15:00:00','Mahesh',
'Madras','Madurai',60)

2 ;
1 row created.
SQL> insert into ticket values('02','12-apr-96','5-may-96','09:00:00','Reema','M
adurai','Madras',60)
2 ;
1 row created.
SQL> insert into ticket values('03','21-apr-96','15-may-96','21:00:00','Aaliya',
'Banglore','Madras',400);
1 row created.
SQL> insert into ticket values('04','25-apr-96','25-may-96','10:00:00','Raju','H
yderabad','Madras',500);
1 row created.
SQL> insert into ticket values('05','30-apr-96','22-may-96','15:00:00','Ramya','
Madras','Cochin',141);
1 row created.
SQL> select * from ticket;
FLIGHT_ID DATE_OF_I DATE_OF_T TIME
PASSENGER_NAME
---------- --------- --------- ---------- -------------------- ---------DESTINATION
TOTAL_FARE
-------------------- ---------01
01-APR-96 10-MAY-96 15:00:00 Mahesh
Madras
Madurai
60
02
12-APR-96 05-MAY-96 09:00:00 Reema
Madras
60

Madurai

03
21-APR-96 15-MAY-96 21:00:00 Aaliya
Madras
400

Banglore

FLIGHT_ID DATE_OF_I DATE_OF_T TIME


PASSENGER_NAME
---------- --------- --------- ---------- -------------------- ---------DESTINATION
TOTAL_FARE
-------------------- ---------04
25-APR-96 25-MAY-96 10:00:00 Raju
Hyderabad

ORIGIN

ORIGIN

Madras

500

05
30-APR-96 22-MAY-96 15:00:00 Ramya
Cochin
141

Madras

3. Display todays date and time in the prompt.


SQL> select systimestamp from dual;
SYSTIMESTAMP
--------------------------------------------------------------------------25-JAN-16 12.05.33.682000 PM +05:30
SQL>

4. Display the absolute value of -184.


SQL> select Abs(-184) from dual;
ABS(-184)
---------184
5.Select a value from the dual and for that value find its cube.
SQL> select power (3,3) from dual;
POWER(3,3)
---------27
6.Display Jill from Jack and Jill using substr operator.
SQL> select substr('Jack and Jill','10','4') from dual;
SUBS
---Jill
7.Display the date 2 months after date of issue of ticket.
SQL> select add_months(date_of_issue,2) from ticket;
ADD_MONTH
--------01-JUN-96
12-JUN-96
21-JUN-96

25-JUN-96
30-JUN-96
8. Display the last day of month of date of travel.
SQL> select last_day(date_of_travel)from ticket;
LAST_DAY(
--------31-MAY-96
31-MAY-96
31-MAY-96
31-MAY-96
31-MAY-96
9. Display the month between date of travel and date of issue.
SQL> select months_between(date_of_issue,date_of_travel) from ticket;
MONTHS_BETWEEN(DATE_OF_ISSUE,DATE_OF_TRAVEL)
--------------------------------------------1.2903226
-.77419355
-.80645161
-1
-.74193548
10. Display the next occurrence of Friday from the day of travel.
SQL> select next_day (date_of_travel,'Friday') from ticket;
NEXT_DAY(
--------17-MAY-96
10-MAY-96
17-MAY-96
31-MAY-96
24-MAY-96
11. Display the first letter of name into capitals.
SQL> select initcap(Passenger_name) from ticket;
INITCAP(PASSENGER_NA
-------------------Mahesh
Reema
Aaliya
Raju

Ramya
12. Display the names into upper case.
SQL> select upper(Passenger_name) from ticket;
UPPER(PASSENGER_NAME
-------------------MAHESH
REEMA
AALIYA
RAJU
RAMYA
13. Convert all destination and source names into lower case
SQL> select lower(origin),lower(destination) from ticket;
LOWER(ORIG LOWER(DESTINATION)
---------- -------------------madras madurai
madurai madras
banglore madras
hyderabad madras
madras cochin
14. Display the first 3 characters of the source name.
SQL> select substr(origin,1,3) from ticket;
SUB
--Mad
Mad
Ban
Hyd
Mad
15. Display the last 3 characters of the source place.
SQL> select substr(origin,length(origin)-2,3) from ticket
2 ;
SUB
--ras

rai
ore
bad
ras
16. Display only that place name that begins with m and replace with b.
SQL> select replace (origin,'M','B') from ticket;
REPLACE(OR
---------Badras
Badurai
Banglore
Hyderabad
Badras
17. Display only three characters from the third character with names of destination.
SQL> select substr(destination,3,3) from ticket;
SUB
--dur
dra
dra
dra
chi
18. Display the rounded value of total fare up to 2 characters.
SQL> select round (total_fare,2) from ticket;
ROUND(TOTAL_FARE,2)
------------------60
60
400
500
141
19.Display the day truncated upto the year for the date of travel.
SQL> select trunc (date_of_travel,'year') from ticket;
TRUNC(DAT
--------01-JAN-96
01-JAN-96
01-JAN-96

01-JAN-96
01-JAN-96
20.Display the day truncated upto the month for date of travel
SQL> select trunc (date_of_travel,'month') from ticket;
TRUNC(DAT
--------01-MAY-96
01-MAY-96
01-MAY-96
01-MAY-96
01-MAY-96

21.Display the day rounded upto the year for date of travel.
SQL> select round (date_of_travel,'year') from ticket;
ROUND(DAT
--------01-JAN-96
01-JAN-96
01-JAN-96
01-JAN-96
01-JAN-96