LAB Assignment - 2
LAB Assignment - 2
LAB Assignment - 2
CSE324 (PL/SQL)
Batch-B1
Avg() Function – it returns the average value of the values in given column.
Sum() Funtion – it return the sum of values in given column.
Insertion:
SQL> insert into dep values(123,'CSE','Delhi');
SQL> insert into dep values(345,'DBMS','Gwalior');
SQL> insert into dep values(567,'MECH','Goa');
SQL> insert into dep values(789,'ELEC','Jaipur');
SQL> insert into dep values(901,'AST','Pune');
Table:
Table 2: EM
EMPNO (NOT NULL, NUMBER (4)), ENAME (VARCHAR2 (10)),
JOB (VARCHAR2 (9)), MGR (NUMBER (4)), HIREDATE (DATE),
SAL (NUMBER (7, 2)), COMM (NUMBER (7, 2)), DEPTNO (NUMBER
(2))
MGR is the empno of the employee whom the employee reports
to. DEPTNO is a foreign key.
Creation:
SQL> create table em(e_no number(4) not null,
2 ename varchar2(15),
3 job varchar2(10),
4 mgr number(5),
5 hiredate date,
6 sal number(7,2),
7 comm number(7,2),
8 deptno references dep(deptno));
Insertion:
SQL> insert into em values(12,'Devashish','coder',20,date '21-10-
01',90000,200,567);
SQL> insert into em values(22,'Mansi','Washer',25,date '21-11-
05',75000,100,345);
SQL> insert into em values(28,'Pradhumn','footer',21,date '21-09-
12',70000,240,901);
SQL> insert into em values(18,'Ambrose','shooter',20,date '21-09-
30',80000,210,567);
SQL> insert into em values(18,'Gaurav','poser',29,date '21-01-
15',85000,190,123);
Table:
SQL> select * from em;
E_NO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- --------------- ---------- ---------- --------- ---------- ---------- ----------
12 Devashish coder 20 01-OCT-21 90000 200 567
22 Mansi Washer 25 05-NOV-21 75000 100 345
28 Pradhumn footer 21 12-SEP-21 70000 240 901
18 Ambrose shooter 20 30-SEP-21 80000 210 567
18 Gaurav poser 29 15-JAN-21 85000 190 123
1. List all the employees who have at least one person reporting
to them.
Query: SQL> select ename from em where e_no in (select mgr from em);
Insertion:
SQL> insert into employee values(12,'Dev','CHD');
SQL> insert into employee values(13,'Manu','CP');
SQL> insert into employee values(15,'Kin','GEL');
SQL> insert into employee values(19,'Amm','ENG');
Table:
Company
(Emp_no:Varchar2, Company_name: varchar2,Salary number)
Creation:
SQL> create table company(empno references employee(empno),
2 cname varchar2(10),
3 sal number(7,2));
Insertion:
SQL> insert into company values(19,'DEX',900);
SQL> insert into company values(13,'REX',200);
SQL> insert into company values(12,'TEX',290);
SQL> insert into company values(15,'GEX',150);
Table:
SOL*Plus -
It is an interactive program that allows us to type in and execute SQL
statements. It also enables us to type in PL/SQL code and send it to the
server to be executed. SQL*Plus is one of the most common front end used
to develop and create stored PL/SQL functions and procedures. It is
command line tool, in that which does not involve DDL, DML, DCL
commands like in SQL. It uses command to manipulate data.