0% found this document useful (0 votes)
17 views

Lab 2

Uploaded by

rajputaslok143
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Lab 2

Uploaded by

rajputaslok143
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

SQL> alter table n drop column roll;

Table altered.

SQL> select * from n;

NAME
-------------------
Angel
Sandip

SQL> delete from n;

2 rows deleted.

SQL> select * from n;

no rows selected

SQL> drop table n;

Table dropped.

SQL> create table student5(roll number(4),name varchar(12),city varchar(12),age


number(2),cgpa float);

Table created.

SQL> insert into student5 values('&roll' , '&name' , '&city' , '&age' , '&cgpa');


Enter value for roll: 4023
Enter value for name: Angel
Enter value for city: Delhi
Enter value for age: 20
Enter value for cgpa: 8.5
old 1: insert into student5 values('&roll' , '&name' , '&city' , '&age' ,
'&cgpa')
new 1: insert into student5 values('4023' , 'Angel' , 'Delhi' , '20' , '8.5')

1 row created.

SQL> /
Enter value for roll: 4024
Enter value for name: Ayusha
Enter value for city: Bbs
Enter value for age: 18
Enter value for cgpa: 9.0
old 1: insert into student5 values('&roll' , '&name' , '&city' , '&age' ,
'&cgpa')
new 1: insert into student5 values('4024' , 'Ayusha' , 'Bbs' , '18' , '9.0')

1 row created.

SQL> /
Enter value for roll: 4025
Enter value for name: Bibek
Enter value for city: patna
Enter value for age: 21
Enter value for cgpa: 8.7
old 1: insert into student5 values('&roll' , '&name' , '&city' , '&age' ,
'&cgpa')
new 1: insert into student5 values('4025' , 'Bibek' , 'patna' , '21' , '8.7')

1 row created.

SQL> /
Enter value for roll: 4026
Enter value for name: Rama
Enter value for city: Delhi
Enter value for age: 22
Enter value for cgpa: 9.0
old 1: insert into student5 values('&roll' , '&name' , '&city' , '&age' ,
'&cgpa')
new 1: insert into student5 values('4026' , 'Rama' , 'Delhi' , '22' , '9.0')

1 row created.

SQL> /
Enter value for roll: 4027
Enter value for name: Aruna
Enter value for city: patna
Enter value for age: 22
Enter value for cgpa: 8.0
old 1: insert into student5 values('&roll' , '&name' , '&city' , '&age' ,
'&cgpa')
new 1: insert into student5 values('4027' , 'Aruna' , 'patna' , '22' , '8.0')

1 row created.

SQL> /
Enter value for roll: 4028
Enter value for name: Mayara
Enter value for city: Mumbai
Enter value for age: 20
Enter value for cgpa: 7.55
old 1: insert into student5 values('&roll' , '&name' , '&city' , '&age' ,
'&cgpa')
new 1: insert into student5 values('4028' , 'Mayara' , 'Mumbai' , '20' , '7.55')

1 row created.

SQL> /
Enter value for roll: 4029
Enter value for name: Amiro
Enter value for city: Kalaiya
Enter value for age: 20
Enter value for cgpa: 8.3
old 1: insert into student5 values('&roll' , '&name' , '&city' , '&age' ,
'&cgpa')
new 1: insert into student5 values('4029' , 'Amiro' , 'Kalaiya' , '20' , '8.3')

1 row created.

SQL> /
Enter value for roll: 4030
Enter value for name: Anisho
Enter value for city: Birgunj
Enter value for age: 24
Enter value for cgpa: 6.5
old 1: insert into student5 values('&roll' , '&name' , '&city' , '&age' ,
'&cgpa')
new 1: insert into student5 values('4030' , 'Anisho' , 'Birgunj' , '24' , '6.5')

1 row created.

SQL> /
Enter value for roll: 4031
Enter value for name: Ram
Enter value for city: Bbs
Enter value for age: 19
Enter value for cgpa: 8.5
old 1: insert into student5 values('&roll' , '&name' , '&city' , '&age' ,
'&cgpa')
new 1: insert into student5 values('4031' , 'Ram' , 'Bbs' , '19' , '8.5')

1 row created.

SQL> /
Enter value for roll: 4032
Enter value for name: Sita
Enter value for city: Kolkata
Enter value for age: 22
Enter value for cgpa: 9.3
old 1: insert into student5 values('&roll' , '&name' , '&city' , '&age' ,
'&cgpa')
new 1: insert into student5 values('4032' , 'Sita' , 'Kolkata' , '22' , '9.3')

1 row created.

SQL> select roll,name,cgpa from student5;

ROLL NAME CGPA


---------- ------------ ----------
4023 Angel 8.5
4024 Ayusha 9
4025 Bibek 8.7
4026 Rama 9
4027 Aruna 8
4028 Mayara 7.55
4029 Amiro 8.3
4030 Anisho 6.5
4031 Ram 8.5
4032 Sita 9.3

10 rows selected.

SQL> update student5 set name = 'Sita' where roll = 4025;

1 row updated.

SQL> select distinct name from student5;

NAME
------------
Mayara
Angel
Ayusha
Ram
Sita
Aruna
Amiro
Rama
Anisho

9 rows selected.

SQL> select name, age, Age + 3 AS AgeAfter3Years from student5;

NAME AGE AGEAFTER3YEARS


------------ ---------- --------------
Angel 20 23
Ayusha 18 21
Sita 21 24
Rama 22 25
Aruna 22 25
Mayara 20 23
Amiro 20 23
Anisho 24 27
Ram 19 22
Sita 22 25

10 rows selected.

SQL> select name,city from student5;

NAME CITY
------------ ------------
Angel Delhi
Ayusha Bbs
Sita patna
Rama Delhi
Aruna patna
Mayara Mumbai
Amiro Kalaiya
Anisho Birgunj
Ram Bbs
Sita Kolkata

10 rows selected.

SQL> select roll,name,city from student5 where city = 'Delhi';

ROLL NAME CITY


---------- ------------ ------------
4023 Angel Delhi
4026 Rama Delhi

SQL> select roll,name,age from student5 where cgpa = 9;

ROLL NAME AGE


---------- ------------ ----------
4024 Ayusha 18
4026 Rama 22

SQL> select roll,name,age from student5 where age > 20;


ROLL NAME AGE
---------- ------------ ----------
4025 Sita 21
4026 Rama 22
4027 Aruna 22
4030 Anisho 24
4032 Sita 22

SQL> select roll,name,age from student5 where age < 20;

ROLL NAME AGE


---------- ------------ ----------
4024 Ayusha 18
4031 Ram 19

SQL> select roll,name,age from student5 where age >= 20;

ROLL NAME AGE


---------- ------------ ----------
4023 Angel 20
4025 Sita 21
4026 Rama 22
4027 Aruna 22
4028 Mayara 20
4029 Amiro 20
4030 Anisho 24
4032 Sita 22

8 rows selected.

SQL> select roll,name,age from student5 where age <= 20;

ROLL NAME AGE


---------- ------------ ----------
4023 Angel 20
4024 Ayusha 18
4028 Mayara 20
4029 Amiro 20
4031 Ram 19

SQL> select roll,name,age from student5 where name != 'Ram';

ROLL NAME AGE


---------- ------------ ----------
4023 Angel 20
4024 Ayusha 18
4025 Sita 21
4026 Rama 22
4027 Aruna 22
4028 Mayara 20
4029 Amiro 20
4030 Anisho 24
4032 Sita 22

9 rows selected.

SQL> select roll,name,age from student5 where name like 'A%';

ROLL NAME AGE


---------- ------------ ----------
4023 Angel 20
4024 Ayusha 18
4027 Aruna 22
4029 Amiro 20
4030 Anisho 24

SQL> select roll,name,age from student5 where name like '%a';

ROLL NAME AGE


---------- ------------ ----------
4024 Ayusha 18
4025 Sita 21
4026 Rama 22
4027 Aruna 22
4028 Mayara 20
4032 Sita 22

6 rows selected.

SQL> select roll,name,age from student5 where name like '%r%';

ROLL NAME AGE


---------- ------------ ----------
4027 Aruna 22
4028 Mayara 20
4029 Amiro 20

SQL> select roll,name,age from student5 where name like '_r%';

ROLL NAME AGE


---------- ------------ ----------
4027 Aruna 22

SQL> select roll,name,age from student5 where name like 'A__%';

ROLL NAME AGE


---------- ------------ ----------
4023 Angel 20
4024 Ayusha 18
4027 Aruna 22
4029 Amiro 20
4030 Anisho 24

SQL> select roll,name,age from student5 where name like 'A___%';

ROLL NAME AGE


---------- ------------ ----------
4023 Angel 20
4024 Ayusha 18
4027 Aruna 22
4029 Amiro 20
4030 Anisho 24

SQL> select roll,name,age from student5 where name like 'A%o';

ROLL NAME AGE


---------- ------------ ----------
4029 Amiro 20
4030 Anisho 24

SQL> select name,city,age from student5 where age >= 10 and age <= 20;

NAME CITY AGE


------------ ------------ ----------
Angel Delhi 20
Ayusha Bbs 18
Mayara Mumbai 20
Amiro Kalaiya 20
Ram Bbs 19

SQL> select name,city,age from student5 where city = 'Bbs' or city = 'Delhi' or
city = 'Patna';

NAME CITY AGE


------------ ------------ ----------
Angel Delhi 20
Ayusha Bbs 18
Rama Delhi 22
Ram Bbs 19

SQL> select name,city,age from student5 order by city ASC;

NAME CITY AGE


------------ ------------ ----------
Ram Bbs 19
Ayusha Bbs 18
Anisho Birgunj 24
Angel Delhi 20
Rama Delhi 22
Amiro Kalaiya 20
Sita Kolkata 22
Mayara Mumbai 20
Sita patna 21
Aruna patna 22

10 rows selected.

SQL> select name,city,age from student5 order by cgpa DESC;


NAME CITY AGE
------------ ------------ ----------
Sita Kolkata 22
Ayusha Bbs 18
Rama Delhi 22
Sita patna 21
Angel Delhi 20
Ram Bbs 19
Amiro Kalaiya 20
Aruna patna 22
Mayara Mumbai 20
Anisho Birgunj 24

10 rows selected.

SQL> select name,age,cgpa from student5 order by cgpa,age,name ASC;

NAME AGE CGPA


------------ ---------- ----------
Anisho 24 6.5
Mayara 20 7.55
Aruna 22 8
Amiro 20 8.3
Ram 19 8.5
Angel 20 8.5
Sita 21 8.7
Ayusha 18 9
Rama 22 9
Sita 22 9.3

10 rows selected.

SQL> CREATE TABLE Person AS SELECT Roll, Name, Age FROM STUDENT5;

Table created.

SQL> insert into Person values('&roll','&name', '&age');


Enter value for roll: 4023
Enter value for name: Angel
Enter value for age: 20
old 1: insert into Person values('&roll','&name', '&age')
new 1: insert into Person values('4023','Angel', '20')

1 row created.

SQL> /
Enter value for roll: 4083
Enter value for name: Sandip
Enter value for age: 21
old 1: insert into Person values('&roll','&name', '&age')
new 1: insert into Person values('4083','Sandip', '21')

1 row created.
SQL> spool off;

You might also like