DMS - Practical 14-21
DMS - Practical 14-21
DMS - Practical 14-21
XI
Pr-15
Create table emp15(empno int primary key,ename varchar2(10),Dept_no int, Job_ID int,
Salary number);
XI
Pr-16
XI
Pr-17
XI
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
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
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;
/