Sie sind auf Seite 1von 46

1.

To CREATE a table in oracle SQL:

CREATE TABLE Supplier8045


(
Sno varchar(2),
Name varchar(50),
Status number(10),
City varchar(10)
);

2. To DESCRIBE a table in oracle SQL:


Describe Supplier8005;
3. To INSERT ROWS in a table in oracle SQL:
INSERT INTO Supplier8005 ( Sno, Name, Status, City) VALUES (‘S1’, ‘Sumit’, 20,
‘Noida’);
INSERT INTO Supplier8005 ( Sno, Name, Status, City) VALUES (‘S2’, ‘Amit’, 20,
‘Gurugram’);
INSERT INTO Supplier8005 ( Sno, Name, Status, City) VALUES (‘S3’, ‘Ankit’, 20,
‘Delhi’);

4.To SELECT FROM a table in oracle SQL:


SELECT * FROM Supplier8045;
5. To ALTER a table in oracle SQL:
ALTER TABLE Supplier8045
ADD PhoneNo varchar(40);

6. To DELETE from a table in oracle SQL:

DELETE FROM Supplier8045 WHERE Name = ‘Amit’;

Before Deletion:

After Deletion:

7. To UPDATE a table in oracle SQL:


Before Updating:

After Updating:

8. To create PRIMARY KEY in a table in oracle SQL:


CREATE TABLE supplier45

Sno varchar(2),

Name varchar(50),

Status number(10),

City varchar(10),

PHONE number(5) PRIMARY KEY

);

Describe supplier45;

INSERT INTO supplier45(Sno, Name, Status, City, PHONE) VALUES ('S1', 'JASON', 20,
'LONDON', 70);

INSERT INTO supplier45(Sno, Name, Status, City, PHONE) VALUES ('S2', 'ROY', 69, 'LONDON',
69);

INSERT INTO supplier45(Sno, Name, Status, City, PHONE) VALUES ('S3', 'HARDIK', 22,
'LONDON', 57);

SELECT * FROM supplier5;


9. To create FOREIGN KEY in a table in oracle SQL:
(

Sno varchar(2),

Name varchar(50),

Status number(10),

City varchar(10),

PHONE number(5) PRIMARY KEY

);

Describe supplier045;

INSERT INTO supplier045(Sno, Name, Status, City, PHONE) VALUES ('S1', 'JASON', 20,
'LONDON', 70);

SELECT * FROM supplier045;

INSERT INTO supplier045(Sno, Name, Status, City, PHONE) VALUES ('S2', 'BISHOP', 20,
'MELBOURNE', 80);

INSERT INTO supplier045(Sno, Name, Status, City, PHONE) VALUES ('S3', 'SAINT', 10,
'BRISBANE', 90);
CREATE TABLE parts045

Pno varchar(2),

Weight number(3),

PHONE number(5),

FOREIGN KEY(PHONE) REFERENCES supplier045(PHONE)

);

Describe parts045;

INSERT INTO parts045(Pno, Weight, PHONE) VALUES ('P1', 68, 80);

SELECT * FROM parts6;

INSERT INTO parts045(Pno, Weight, PHONE) VALUES ('P2', 78, 80);

Describing Supplier Table:

Displaying Supplier Table


Describing Parts Table

Using Foreign Key in Parts Table from Suppliers Table

10. To use Select DISTINCT function in a table in oracle SQL:

ORIGINAL TABLE

SELECTING DISTINCT NAME


11. To use Select COUNT function in a table in oracle SQL:

12. To use Select AVG function in a table in oracle SQL:

13. To use Select MIN function in a table in oracle SQL:


15. To use Select MAX function in a table in oracle SQL:

16. To use Select SUM function in a table in oracle SQL:

17. To use SYSDATE function in a table in oracle SQL:


18. To use GROUP BY function in a table in oracle SQL:
CREATE TABLE a45
(
NAME varchar(20),
AGE number(2),
SALARY number(10)
);
Describe a45;
INSERT INTO a45 VALUES('YO', 20, 40000);
INSERT INTO a45 VALUES('JASON', 40, 20000);
INSERT INTO a45 VALUES('LAKSHYA', 43, 40000);
INSERT INTO a45 VALUES('JASON', 48, 20000);
INSERT INTO a45 VALUES('CRAIG', 42, 30000);
INSERT INTO a45 VALUES('MARTIN GARRIX', 27, 70000);
SELECT * FROM a45;
SELECT NAME, SUM(SALARY) FROM a45
GROUP BY NAME;

Initial table

Grouped By Name:
19.To JOIN (INNER, LEFT, RIGHT, FULL) joins in oracle SQL.
CREATE TABLE supplier05

Sno varchar(2) ,

Name varchar(50),

Status number(10),

City varchar(10),

PHONE number(5)

);

CREATE TABLE parts05

Pno varchar(2),

PHONE number(5)

);

Describe parts05;

Describe supplier05;

INSERT INTO supplier05(Sno, Name, Status, City, PHONE) VALUES ('S1', 'JASON', 20, 'LONDON', 70);

INSERT INTO supplier05(Sno, Name, Status, City, PHONE) VALUES ('S2', 'ROY', 69, 'AUSTRALIA', 69);

INSERT INTO supplier05(Sno, Name, Status, City, PHONE) VALUES ('S3', 'HARDIK', 22, 'CANADA', 57);

INSERT INTO supplier05(Sno, Name, Status, City, PHONE) VALUES ('S4', 'LAKSHYA', 20, 'TOKYO', 55);

INSERT INTO supplier05(Sno, Name, Status, City, PHONE) VALUES ('S5', 'STATHAM', 40, 'BRISBANE', 12);

INSERT INTO supplier05(Sno, Name, Status, City, PHONE) VALUES ('S6', 'BISHOP', 45, 'AUCKLAND', 34);

INSERT INTO supplier05(Sno, Name, Status, City, PHONE) VALUES ('S7', 'MECHANIC', 70, 'DENVER', 44);

SELECT * FROM supplier05;

INSERT INTO parts05(Pno, PHONE) VALUES ('P1', 70);


INSERT INTO parts05(Pno, PHONE) VALUES ('P2', 69);

INSERT INTO parts05(Pno, PHONE) VALUES ('P3', 57);

INSERT INTO parts05(Pno, PHONE) VALUES ('P4', 15);

INSERT INTO parts05(Pno, PHONE) VALUES ('P5', 12);

INSERT INTO parts05(Pno, PHONE) VALUES ('P6', 34);

INSERT INTO parts05(Pno, PHONE) VALUES ('P7', 27);

Select * from parts05;

SUPPLIER TABLE

PARTS TABLE
➢ INNER JOIN
SELECT parts05.Pno, supplier05.Name FROM supplier05

INNER JOIN parts05

ON supplier05.PHONE = parts05.PHONE;

➢ LEFT JOIN
SELECT parts05.Pno, supplier05.Name FROM supplier05

LEFT JOIN parts05

ON supplier05.PHONE = parts05.PHONE;

➢ RIGHT JOIN
SELECT parts05.Pno, supplier05.Name FROM supplier05

RIGHT JOIN parts05

ON supplier05.PHONE = parts05.PHONE;

➢ FULL JOIN
SELECT parts05.Pno, supplier05.Name FROM supplier05

FULL JOIN parts05

ON supplier05.PHONE = parts05.PHONE;
EXPERIMENT

Aim: Create the following tables and execute given queries.

1. Course(course_no char(4), course_name varchar(20))


2. Course_fee(course_no char(4), full_part char(1) (F/P), fees number(10))
course_no and full_part should be unique
3. Student(prospectus_no number(10), name varchar(20), address
varchar(30), phone_no number(11), D_O_B date, total_amt
number(10,2), amt_paid number(10,2), installment char(1) (I/F))
4. Installment(prospectus_no number(10) (foreign key) on delete cascade,
installment_amt number(10,2), due_dt date, paid char(1) (P,U))
prospectus_no and due_dt should be unique
5. Course_taken(prospectus_no number(10) (foreign key), course_no
char(4), start_dt date, full_part char(1) (F/P), time_slot char(2),
performance varchar(20))

SQL Platform Used: Oracle Database 19c Enterprise Edition - 19.5.0.0.0

Queries:

Creating Tables and Inserting Data

create table Course (course_no char(4) primary key, course_name varchar(20));

insert into Course values ('C101', 'O System');

insert into Course values ('C102', 'Material Science');

insert into Course values ('C103', ‘Chemistry');

insert into Course values ('C104', 'Automata');


insert into Course values ('C105', 'DBMS');

insert into Course values ('C106', 'JAVA PROGRAMMING');

insert into Course values ('C107', 'Compilers');

insert into Course values ('C108', 'Python');

insert into Course values ('C109', 'Computer Graphics');

insert into Course values ('C110', 'Computer Networks');

select * from Course;

COURSE_NO COURSE_NAME
C101 O System
C102 Material Science
C103 Chemistry
C104 Automata
C105 DBMS
C106 JAVA PROGRAMMING
C107 Compilers
C108 Python
C109 Computer Graphics
C110 Computer Networks
create table Course_fee(course_no char(4) references Course(course_no),
full_part char(1) check (full_part='P' or full_part='F'), fees number(10));

insert into Course_fee values ('C101', 'A', 20153);

insert into Course_fee values ('C102', 'B', 32153);

insert into Course_fee values ('C103', 'C', 32673);

nsert into Course_fee values ('C104', 'D', 25543);

insert into Course_fee values ('C105', 'F', 19214);

insert into Course_fee values ('C106', 'F', 11328);

insert into Course_fee values ('C107', 'P', 11872);

insert into Course_fee values ('C108', 'F', 21634);

insert into Course_fee values ('C109', 'F', 16752);

insert into Course_fee values ('C110', 'F', 12182);

select * from Course_fee;

COURSE_NO FULL_PART FEES


C101 A 20153
C102 B 32153

C103 C 32673

C104 D 25543

C105 F 19214

C106 F 11328

C107 P 11872

C108 F 21634

C109 F 16752

C110 F 12182

create table Student (prospectus_no number(10) primary key, name varchar(20),


address varchar(30), phone_no number(11), D_O_B date,total_amt
number(10,2), amt_paid number(10,2), installment char(1) check (installment =
'I' or installment = 'F'));

insert into Student values (218053, 'Ganesh', 'Delhi', 9999999999, '01-aug-00',


20153, 20153, 'F');

insert into Student values (218044, 'Gaitonde', 'Narnaul', 8888888888, '09-may-


00', 32153, 20153, 'I');

insert into Student values (218002, 'Sartaj', 'Odisha', 7777777777, '12-sep-99',


32673, 32673, 'F');

insert into Student values (218060, 'Singh', 'Kanpur', 6666666666, '03-jul-01',


25543, 25000, 'I');
.

insert into Student values (218045, 'Hardik', 'Yamunanagar', 5555555555, '03-


jun-00', 19214, 19214, 'F');

insert into Student values (218004, 'Ankita', 'Patna', 4444444444, '27-dec-99',


11328, 11328, 'F');

insert into Student values (218038, 'Manas', 'Dehradun', 3333333333, '31-oct-


00', 11872, 10000, 'I');

insert into Student values (218061, 'Dhruv', 'Uttrakhand', 2222222222, '05-oct-


00', 21634, 21634, 'F');

insert into Student values (218010, 'Deepak', 'Dehradun', 8888444456, '13-nov-


00', 16752, 16750, 'I');

insert into Student values (218057, 'Anshu', 'Noida', 2277663399, '27-oct-99',


12182, 12182, 'F');

select * from Student;

D_
PROSPEC NA ADDR PHON O_ TOTAL AMT_ INSTAL
TUS_NO ME ESS E_NO B _AMT PAID LMENT
218053 Gane Delhi 999999 01- 20153 20153 F
sh 9999 AU
G-
00
218044 Gait Narnaul 888888 09- 32153 20153 I
onde 8888 MA
Y-
00
218002 Sarta Odisha 777777 12- 32673 32673 F
j 7777 SEP
-99
218060 Sing Kanpur 666666 03- 25543 25000 I
h 6666 JUL
-01
218045 Hard Yamun 555555 03- 19214 19214 F
ik anagar 5555 JU
N-
00
218004 Anki Patna 444444 27- 11328 11328 F
ta 4444 DE
C-
99
218038 Man Dehrad 333333 31- 11872 10000 I
as un 3333 OC
T-
00
218061 Dhru Uttrakh 222222 05- 21634 21634 F
v and 2222 OC
T-
00
218010 Deep Dehrad 888844 13- 16752 16750 I
ak un 4456 NO
V-
00
218057 Ansh Noida 227766 27- 12182 12182 F
u 3399 OC
T-
99

create table Installment (prospectus_no number(10) references


Student(prospectus_no) on delete cascade unique, installment_amt
number(10,2), due_dt date unique, paid char(1) check (paid='P' or paid='U'));
insert into Installment values (218044, 100000, '10-mar-20', 'U');

insert into Installment values (218060, 343, '11-mar-20', 'P');

insert into Installment values (218038, 1872, '12-mar-20', 'U');

insert into Installment values (218010, 2, '13-mar-20', 'P');

select * from Installment;

PROSPECTUS_NO INSTALLMENT_AMT DUE_DT PAID


218044 100000 10-MAR-20 U
218060 343 11-MAR-20 P
218038 1872 12-MAR-20 U
218010 2 13-MAR-20 P

create table Course_taken (prospectus_no number(10) references


Student(prospectus_no), course_no char(4) references Course(course_no),
start_dt date, full_part char(1) check (full_part='P' or full_part='F'), time_slot
char(2), performance varchar(20))

insert into Course_taken values (218053, 'C101', '01-mar-20','F','09','Good');

insert into Course_taken values (218044, 'C102', '01-mar-20','P','10','Good');

insert into Course_taken values (218002, 'C103', '01-mar-20','P','11','Good');

insert into Course_taken values (218060, 'C104', '01-mar-20','F','12','Good');


insert into Course_taken values (218045, 'C105', '01-mar-20','F','13','Good');

insert into Course_taken values (218004, 'C106', '01-mar-20','F','14','Good');

insert into Course_taken values (218038, 'C107', '01-mar-20','P','15','Good');

insert into Course_taken values (218061, 'C108', '01-mar-20','F','16','Good');

insert into Course_taken values (218010, 'C109', '01-mar-20','F','17','Good');

insert into Course_taken values (218057, 'C110', '01-mar-20','F','18','Good');

select * from Course_taken;

PROSPECTU COURSE START FULL_P TIME_S PERFORM


S_NO _NO _DT ART LOT ANCE
218053 C101 01- F 09 Good
MAR-
20
218044 C102 01- P 10 Good
MAR-
20
218002 C103 01- P 11 Good
MAR-
20
218060 C104 01- F 12 Good
MAR-
20
218045 C105 01- F 13 Good
MAR-
20
218004 C106 01- F 14 Good
MAR-
20
218038 C107 01- P 15 Good
MAR-
20
218061 C108 01- F 16 Good
MAR-
20
218010 C109 01- F 17 Good
MAR-
20
218057 C110 01- F 18 Good
MAR-
20

Executing Queries:

• Retrieve name and course no of all the students.


select name, course_no from Student, Course_taken where
Student.prospectus_no = Course_taken.prospectus_no;

NAME COURSE_NO
Ganesh C101
Gaitonde C102
Sartaj C103
Singh C104
Hardik C105
Ankita C106
Manas C107
Dhruv C108
Deepak C109
Anshu C110

• List the names of students who have paid the full amount at the time of
admission.
select name from Student where installment = 'F';

NAME
Ganesh
Sartaj
Hardik
Ankita
Dhruv
Anshu

• Find the names of students starting with A.


select name from Student where name like 'A%';

NAME
Singh

Ankita

Anshu

• Print the names of students whose total amount is not equal to amount
due.
select name from Student where total_amt<>(total_amt-amt_paid);

NAME
Ganesh
Gaitonde
Sartaj
Singh
Hardik
Ankita
Manas
Dhruv
Deepak
Anshu

• Determine the maximum and minimum course fees.


select min(fees), max(fees) from Course_fee;

MIN(FEES) MAX(FEES)
11328 32673

• Print the details of courses whose fees are between 15000 and 20000.
select Course.course_no, course_name, full_part from Course, Course_fee
where Course.course_no = Course_fee.course_no and fees between 15000 and
20000;

COURSE_NO COURSE_NAME FULL_PART


C105 DBMS F
C109 Computer F
Graphics

• Display the date of birth in DD-MONTH-YYYY format


select D_O_B from student;

D_O_B
01-AUG-00
09-MAY-00
12-SEP-99
03-JUL-01
03-JUN-00
27-DEC-99
31-OCT-00
05-OCT-00
13-NOV-00
27-OCT-99

• Change the course_name from JAVA to Core JAVA.


update course set course_name = 'Core JAVA' where course_name = 'JAVA';
1 row(s) updated.

• Select the students who have not yet paid full amount of fees.
select Installment.prospectus_no, Student.name from Student, Installment where
Student.prospectus_no = Installment.prospectus_no and Installment.Paid = 'U';

PROSPECTUS_NO NAME
218044 Harshit

218038 Manas

• Increase the fee of oracle by 50%.


update Course_fee set fees = fees + (0.5*fees) where course_no in (select
t.course_no from course t where t.course_name = 'DBMS');
EXPERIMENT

Aim: Create the following tables and execute given queries.

1. SUPPLIER(SNO, SNAME, STATUS, CITY)


2. PARTS(PNO, PNAME, COLOR, WEIGHT, CITY)
3. PROJECT(JNO, JNAME, CITY)
4. SPJ(SNO, PNO, JNO, QTY)
SQL Platform Used: Oracle Database 19c Enterprise Edition - 19.5.0.0.0

Queries:

Creating Tables and Inserting Data

create table Supplier (Sno char(3) primary key, Sname varchar(10), Status int,
City varchar(10));
insert into Supplier values ('S1','SRK',20,'Delhi');
insert into Supplier values ('S2','Selmon',55,'Noida');
insert into Supplier values ('S3','KRK',13,'Gurgoan');
insert into Supplier values ('S4','Udit',24,'Pune');
insert into Supplier values ('S5','Ramesh',42,'Mumbai');
insert into Supplier values ('S6','Amit',30,'Bhopal');
insert into Supplier values ('S7','Vikas',12,'Jaipur');
insert into Supplier values ('S8','Suraj',43,'Chennai');
insert into Supplier values ('S9','Shubh',32,'Bangalore');
insert into Supplier values ('S10','Paras',29,'Chandigarh');
select * from Supplier;

SNO SNAME STATUS CITY


S1 SRK 20 Delhi
S2 Selmon 55 Noida
S3 KRK 13 Gurgoan
S4 Udit 24 Pune
S5 Ramesh 42 Mumbai
S6 Amit 30 Bhopal
S7 Vikas 12 Jaipur
S8 Suraj 43 Chennai
S9 Shubh 32 Bangalore
S10 Paras 29 Chandigarh

create table Parts (Pno char(3) primary key, Pname varchar(10), Color
varchar(10), Weight int, City varchar(10));

insert into Parts values ('P1','Penchkass','Blue',120,'Delhi');

insert into Parts values ('P2','Plass','Red',84,'Noida');

insert into Parts values ('P3','Bolt','Green',10,'Gurgoan');


insert into Parts values ('P4','Pin','Yellow',2,'Pune');
insert into Parts values ('P5','Spanner','Magenta',23,'Mumbai');
insert into Parts values ('P6','Rivet','Cyan',7,'Bhopal');
insert into Parts values ('P7','Rinch','Black',35,'Jaipur');
insert into Parts values ('P8','Nail','Orange',4,'Chennai');
insert into Parts values ('P9','Wire','Pink',12,'Bangalore');
insert into Parts values ('P10','Washer','White',8,'Chandigarh');
select * from Parts;

PNO PNAME COLOR WEIGHT CITY


P1 Penchkass Blue 120 Delhi
P2 Plass Red 80 Noida
P3 Bolt Green 10 Gurgoan
P4 Pin Yellow 2 Pune
P5 Spanner Magenta 23 Mumbai
P6 Rivet Cyan 7 Bhopal
P7 Rinch Black 35 Jaipur
P8 Nail Orange 4 Chennai
P9 Wire Pink 12 Bangalore
P10 Washer White 8 Chandigarh

create table Project (Jno char(3) primary key, Jname varchar(10), City
varchar(20));
insert into Project values ('J1','DLF','Delhi');

insert into Project values ('J2','Pacific','Noida');

insert into Project values ('J3','Omaxe','Gurgoan');

insert into Project values ('J4','Ansal','Pune');

insert into Project values ('J5','Everest','Mumbai');

insert into Project values ('J6','Welcome','Bhopal');

insert into Project values ('J7','East West','Jaipur');

insert into Project values ('J8','Smarts','Chennai');

insert into Project values ('J9','Exhibits','Bangalore');

insert into Project values ('J10','HBTW','Chandigarh');

select * from Project;

JNO JNAME CITY


J1 DLF Delhi
J2 Pacific Noida
J3 Omaxe Gurgoan
J4 Ansal Pune
J5 Everest Mumbai
J6 Welcome Bhopal
J7 East West Jaipur
J8 Smarts Chennai
J9 Exhibits Bangalore
J10 HBTW Chandigarh

create table SPJ (Sno char(3) references Supplier(Sno), Pno char(3) references
Parts(Pno), Jno char(3) references Project(Jno), Qty int);

insert into SPJ values ('S1','P1','J1',250);


insert into SPJ values ('S2','P2','J2',500);

insert into SPJ values ('S3','P3','J3',1200);

insert into SPJ values ('S4','P4','J4',2400);

insert into SPJ values ('S5','P5','J5',600);

insert into SPJ values ('S6','P6','J6',1800);

insert into SPJ values ('S7','P7','J7',2700);

insert into SPJ values ('S8','P8','J8',3100);

insert into SPJ values ('S9','P9','J9',900);

insert into SPJ values ('S10','P10','J10',1400);

select * from SPJ;

SNO PNO JNO QTY


S1 P1 J1 200
S2 P2 J2 500
S3 P3 J3 1200
S4 P4 J4 2400
S5 P5 J5 600
S6 P6 J6 1800
S7 P7 J7 2700
S8 P8 J8 3100
S9 P9 J9 900
S10 P10 J10 1400

Executing Queries:

• Get sno values for suppliers who supply project j1.


select sno from spj where jno = 'J1';
SNO
S1

• Get sno values for suppliers who supply project j1 with part p1.
select sno from spj where jno = 'J1' and pno = 'P1';

SNO
S1

• Get jname values for projects supplied by supplier s1.


select Jname from Project, SPJ where Project.Jno = SPJ.Jno and SPJ.Sno = 'S1';

JNAME
DLF

• Get color values for parts supplied by supplier s1.


select Color from Parts, SPJ where Parts.Pno = SPJ.Pno and SPJ.Sno = 'S1';

COLOR
Blue

• Get pno values for parts supplied to any project in Pune.


select Pno from SPJ, Project where SPJ.Jno = Project.Jno and City = 'Pune';

PNO
P4

• Get sno values for suppliers who supply project j1 with a blue part.
select Sno from SPJ, Parts where SPJ.Pno = Parts.Pno and Jno='J1' and
Color='Blue';
SNO
S1

• Get sno values for suppliers who supply a Noida or Delhi project with a
red part.
select Sno from SPJ, Parts, Project where SPJ.Pno = Parts.Pno and SPJ.Jno =
Project.Jno and Parts.Color = 'Red' and (Project.City = 'Delhi' or Project.City =
'Noida');

SNO
S2

• Get pno values for parts supplied to any project by a supplier in the same
city.
select Pno from SPJ, Project, Supplier where SPJ.Jno = Project.Jno and SPJ.Sno
= Supplier.Sno and Supplier.City = Project.City;

PNO
P1
P2
P3
P4
P5
P6
P7
P8
P9
P10

• Get pno values for parts supplied to any project in Bhopal by a supplier in
Bhopal.
select Pno from SPJ, Project, Supplier where SPJ.Jno = Project.Jno and SPJ.Sno
= Supplier.Sno and Supplier.City = Project.City and Supplier.City = 'Bhopal';

PNO
P6

• Get jnames for those project which are supplied by supplier Shubh.
select Jname from Project, SPJ, Supplier where SPJ.Jno = Project.Jno and
SPJ.Sno = Supplier.Sno and Supplier.Sname = 'Shubh';

JNAME
Exhibits

• Get sname values for suppliers who supply to projects j1 and j2.
select Sname from Supplier, SPJ where SPJ.Sno = Supplier.Sno and (Jno='J1' or
Jno='J2');

SNAME
SRK
Selmon

• Get pno values for parts supplied to all projects in Pune.


select Pno from SPJ, Project where SPJ.Jno = Project.Jno and City = 'Pune';
PNO
P4

• Get total quantity of part p1 supplied by supplier s1.


select Sum(Qty) from SPJ where Sno = 'S1' and Pno = 'P1';

SUM(QTY)
200

• Get the total number of projects supplied by supplier s3.


select count(Sno) from SPJ where Sno = 'S3';

COUNT(SNO)
1

• Change color of all red parts to orange.


update Parts set Color='Orange' where Color='Red';
Experiment

SQL Code:-

create table employee(Firstname char(20),Lastname char(20),Jobtitle char(30),


Mid int,Salary int,Commission char(2),Eid int,Hiredate date,Fmday char(15));

insert into employee values('Harshit','Aggarwal','Marketing


executive',NULL,50000,'Y',1001,'09-May-2017','Monday');

insert into employee values('Hardik','Garg','Sales


executive',NULL,80000,'Y',1002,'03-Oct-2016','Monday');

insert into employee values('Sachin','Gupta','Stock


clerk',1113,40000,'N',1003,'01-Nov-2016','Tuesday');

insert into employee values('Poonam','Aggarwal','Sales


representative',1112,70000,'Y',1004,'01-Oct-2016','Wednesday');

insert into employee values('Manas','Dobhal','Marketing


representative',1115,50000,'Y',1005,'04-Jan-2017','Saturday');

insert into employee


values('Deepak','Tiwari','Accountant',NULL,90000,'N',1006,'01-Aug-
2017','Thursday');

insert into employee


values('Devansh','Srivastav','HR',NULL,100000,'Y',1007,'15-Oct-
2016','Friday');
insert into employee
values('Narendra','Modi','CEO',NULL,150000,'Y',1008,'01-Oct-
2015','Monday');

select * from employee;

create table dept(Mid int, Dname char(30));

insert into dept values(1115,'Marketing');

insert into dept values(1112,'Sales');

insert into dept values(1113,'Stock');

select * from dept;

select Lastname, Jobtitle from employee where Mid IS NULL;

ALTER TABLE employee

Add Com_value int;

Update employee

Set Com_value=70000

where eid=1001;

Update employee

Set Com_value=30000

where eid=1002;

Update employee
Set Com_value=60000

where eid=1003;

Update employee

Set Com_value=40000

where eid=1004;

Update employee

Set Com_value=50000

where eid=1005;

Update employee

Set Com_value=30000

where eid=1006;

select Lastname,Salary,Com_value from employee where Commission='Y'


ORDER BY Salary DESC, Com_value DESC ;

select Eid,Lastname,Salary,Dname from employee,dept where employee.Mid IS


not null AND employee.Mid=dept.Mid ;

select Lastname from employee where Lastname like '__a%';

select Lastname from employee where Lastname like '%a' and Lastname like
'%e';

select Lastname,Jobtitle,Salary from employee where Jobtitle='Sales


representative' OR Jobtitle='Stock clerk' AND Salary<>80000 AND
Salary<>90000;
select Eid,Lastname,Salary, ROUND(Salary*1.155,0) "NEW SALARY" from
employee;

SELECT Lastname ||' earns '|| TO_CHAR(Salary, 'fm$99,999.00') || ' monthly


but wants '|| TO_CHAR(salary * 3 ) "DREAM SALARIES" FROM employee;

SELECT Lastname, LPAD(Salary, 15, '$') Salary FROM employee;

SELECT Lastname,
Hiredate,TO_CHAR(NEXT_DAY(ADD_MONTHS(Hiredate,
6),'MONDAY'),'fmDay, "the" Ddspth "of" Month, YYYY') REVIEW FROM
employee;

SELECT Lastname, Hiredate,TO_CHAR(Hiredate, 'DAY') DAY FROM


employee ORDER BY TO_CHAR(hiredate-1, 'd');

Output:-
Open Ended Experiment

Das könnte Ihnen auch gefallen