DMS - Practical 14-21

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Pr-14

XI

1. Select min(Sal ) as Minimum,Max(Sal) as Maximum,Sum(Sal) as sum , Avg(sal) as


Average from Emp14;
2. select count(empno) as No_of_Manager from emp14 where Job='Manager';
3. select max(sal)-min(sal) as Differece from emp14;
4. select count(empno) from emp14 where deptno=10 and comm>=0;

Pr-15

Create table emp15(empno int primary key,ename varchar2(10),Dept_no int, Job_ID int,
Salary number);

Create table Dept15(Deptno int primary key references emp15(empno),dept_name


varchar2(10),Loc varchar2(10));

1. select * from emp15;


Select * from dept15;
2. select dept_no ,avg(salary) from emp15 group by dept_no;
3. select dept_no ,sum(salary) as Total_Sal from emp15 group by dept_no having
sum(salary) >20000;
4. select * from emp15 order by dept_no desc;

XI

1. select dept_no, min(salary) as Min_Sal from emp15 group by dept_no;


2. select dept_no, sum(salary) as Total_Sal from emp15 group by dept_no;
3. select dept_no,count(empno) as No_of_Emp from emp15 group by dept_no having
count(empno) >5;
4. select * from emp15 order by ename;
5. select empno,deptno from dept15 group by dept_name;

Pr-16

XI

create table emp16 (Empid int,Empname varchar2(10),Salary number,Deptno number,RO


varchar2(10));

create table dept16(Deptno number,Deptname varchar2(10), Loc varchar2(10));


1.select Emp16.empid,emp16.empname,dept16.deptno,dept16.deptname,dept16.loc from
Emp16 full outer join Dept16 on Emp16.deptno=Dept16.deptno where
emp16.empname=’Nikhil’;

2. select Emp16.empname from Emp16 inner join Dept16 on Dept16.deptno=Emp16.deptno


where Dept16.deptname='Sales';

3. select Emp16.empname from Emp16 inner join Dept16 on Dept16.deptno=Emp16.deptno


where Dept16.deptname not in ('Sales');

4. Select epmname ,salary from emp16 where RO=’Sumit Patil’;

Pr-17

XI

1. create view emp_view as select emp_no ,e_name ,Salary from emp;


view created
Select * from Emp_view;

Emp_No E_Name Salary


101 ABC 10000
105 PQR 20000

2. Update emp_view set e_name=’Jay’ where Emp_no=101


View updated
Select * from Emp_view;

Emp_No E_Name Salary


101 Jay 10000
105 PQR 20000

3. Delete from Emp_view where Emp_No=105;


View updated
Select * from Emp_view;

Emp_No E_Name Salary


101 Jay 10000

4. Drop view Emp_view;


View dropped
Error Message-Object doesn’t exist

5. Update Dept_view set Loc=’Mumbai’ where Dept_No=10;


6. create index dept_simple_index on dept17(deptno);
Output – Index created
7. create index dept_Composite_index on dept17(deptno,deptname);
Output – Index created
8. Drop index dept_simple_index;
Output – Index dropped
Drop index dept_Composite_index;
Output – Index dropped
9. Create index raj on emp(empno,ename);
Output – Index created

1. A. Output- Sequence created


B. Output- Sequence altered
C. Output - Sequence dropped

PR-18

1.

DECLARE
num1 NUMBER := &get_num;
BEGIN
IF num1 > 0 THEN
DBMS_OUTPUT.PUT_LINE ('The number '||num1||' is Positive number');
END IF;
END;
/
Output :
Enter value for get_num: 10
old 2: num1 NUMBER := &get_num;
new 2: num1 NUMBER := 10;
The number 10 is Positive number

PL/SQL procedure successfully completed.

2.

DECLARE
age NUMBER := &get_age;
BEGIN
IF age > 18 THEN
DBMS_OUTPUT.PUT_LINE ('You can Vote');
Else
DBMS_OUTPUT.PUT_LINE (' You Cannot Vote');
END IF;
END;
/
Output:
Enter value for get_age: 25
old 2: age NUMBER := &get_age;
new 2: age NUMBER := 25;
You can Vote

PL/SQL procedure successfully completed.

3.

DECLARE
per number := &get_per;
BEGIN
IF ( per >= 75) THEN
dbms_output.put_line('Distinction' );
ELSIF ( per >= 60 and per <=75 ) THEN
dbms_output.put_line('First class' );
ELSIF ( per >= 45 and per <60 ) THEN
dbms_output.put_line('Second Class' );
ELSIF ( per >= 40 and per <45 ) THEN
dbms_output.put_line('Pass Class' );

ELSE
dbms_output.put_line('failed');
END IF;

END;
/

PR-19

XI

1. declare
n number;
i number;

begin
n:=&n;

for i in 1..10
loop
dbms_output.put_line(n||' x '||i||' = '||n*i);
end loop;
end;
/

2.
declare
num number := &get_num;
fact number := 1;
temp number;
begin
temp :=num;
while( temp>0 )
loop
fact := fact*temp;
temp := temp-1;
end loop;
dbms_output.put_line('factorial of '|| num || ' is ' || fact);
end;
/

3.
DECLARE
counter NUMBER;
k NUMBER;
BEGIN
FOR n IN 1..50 LOOP
counter := 0;
k := floor(n/2);
FOR i IN 2..k LOOP
IF (mod(n, i) = 0 ) THEN
counter := 1;
END IF;
END LOOP;
IF (counter = 0) THEN
DBMS_OUTPUT.PUT_LINE(n||' is prime number');
END IF;
END LOOP;
END;
/

PR-20

XI

1.

DECLARE
num NUMBER(3) := 1;
sum1 NUMBER(4) := 0;
BEGIN
WHILE num <= 10 LOOP
dbms_output.Put_line(num);
sum1 := sum1 + num;
num := num + 2;

END LOOP;
dbms_output.Put_line('Sum of all odd numbers is '|| sum1);
END;
/

2.
DECLARE
a NUMBER := 1;
BEGIN
<<my_label>>
WHILE a <= 10 LOOP
DBMS_OUTPUT.PUT_LINE('Value of a: ' || a);
a := a + 1;

IF a = 5 THEN
GOTO my_label;
END IF;
END LOOP;
END;

3.

DECLARE
day_number NUMBER := &get_day;
day_name VARCHAR2(20);
BEGIN
CASE day_number
WHEN 1 THEN
day_name := 'Monday';
WHEN 2 THEN
day_name := 'Tuesday';
WHEN 3 THEN
day_name := 'Wednesday';
WHEN 4 THEN
day_name := 'Thursday';
WHEN 5 THEN
day_name := 'Friday';
WHEN 6 THEN
day_name := 'Saturday';
WHEN 7 THEN
day_name := 'Sunday';
ELSE
day_name := 'Invalid day';
END CASE;
DBMS_OUTPUT.PUT_LINE('The day is: ' || day_name);
END;
/

PR-21
XI
1.
create table stud1(Roll_No int, Name Varchar2(10),Dept varchar2(3),Fees number );

DECLARE
my_record stud1%Rowtype;
Cursor c1 is select * from stud1 where Dept='CO';
Begin
Open c1;
Loop
Fetch c1 into my_record;
Exit when c1%notfound;
DBMS_OUTPUT.PUT_LINE(' Roll_No= '||my_record.ROLL_NO||'NAME ='||
my_record.Name||' Dept= '||my_record.Dept||' FEES= '||my_record.Fees );
End Loop;
Close c1;
End;
/

2.

DECLARE
my_record stud1%Rowtype;
Cursor c1 is select * from stud1 where mod( Roll_No ,2 )=0;
Begin
Open c1;
Loop
Fetch c1 into my_record;
Exit when c1%notfound;
DBMS_OUTPUT.PUT_LINE(' Roll_No= '||my_record.ROLL_NO||'NAME ='||
my_record.Name||' Dept= '||my_record.Dept||' FEES= '||my_record.Fees );
End Loop;
Close c1;
End;
/

3.

DECLARE
my_record stud1%Rowtype;
Cursor c1 is select * from stud1 where fees>2000;
Begin
Open c1;
Loop
Fetch c1 into my_record;
Exit when c1%notfound;
DBMS_OUTPUT.PUT_LINE(' Roll_No= '||my_record.ROLL_NO||'NAME ='||
my_record.Name||' Dept= '||my_record.Dept||' FEES= '||my_record.Fees );
End Loop;
Close c1;
End;
/

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy