SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
http://placementkit.blogspot.com/


PL / SQL PROGRAMS

P1. WRITE A NESTED PROGRAM TO ADD AND TO MULTIPLY TWO NUMBERS.
DECLARE
N1 number;
N2 number;
Sum number ;
BEGIN
Sum := N1+N2 ;
<< inner_block >>
DECLARE
Prod number;
BEGIN
Prod := N1 * N2 ;
Dbms_output.put_line( Product Value =   prod );
END inner_block ;
Dbms_output.put_line( Sum Value =     sum);
END;

P2. WRITE A PROGRAM TO CALCULATE THE SIMPLE INTEREST AND COMPUND
INTEREST ,
IF P, N, R ARE GIVEN.
declare
p number(9,2) ;
n number(9,2) ;
r number(9,2) ;
si number(9,2) := 0;
ci number(9,2) := 0;
begin
p := &principal_amount;
n := &no_of_years;
r := &rate_of_interest;
si := p*n*r/100;
ci := p*(1+r/100)**n;
dbms_output.put_line('simple interset ='  si);
dbms_output.put_line('compound interset ='     ci);
end;

SQL> /
Enter value for principal_amount: 10000
old 8: p:=&principal_amount;
new 8: p:=10000;
Enter value for no_of_years: 5
old 9: n:=&no_of_years;
new 9: n:=5;
Enter value for rate_of_interest: 10.5
old 10: r:=&rate_of_interest;
new 10: r:=10.5;
simple interset =5250
compound interset =16474.47
PL/SQL procedure successfully completed.
PROGRAM BASED ON IF LOOP
http://placementkit.blogspot.com/


P3 . Write a program to check greatest of two numbers :
declare
a number(3) :=20;
b number(3) :=10;
begin
if a>b then
dbms_output.put_line('a is the greatest : ' a);
else
dbms_output.put_line('B is the greatest : ' b);
end if;
end;

SQL> /
a is the greatest : 20
PL/SQL procedure successfully completed.

P4. Given 2 sides of a rectangle .Write a program to find out its area is gr
eater than its perimeter or not .
declare
l number;
b number;
ar number;
pr number;
begin
l := &l;
b := &b;
ar := l*b;
pr := 2*(l+b);
if ar > pr then
dbms_output.put_line('the area iS > its perimeter' 'area = ' ar 'perimet
er = ' pr);
else
dbms_output.put_line('the area iS < its perimeter' ' area = ' ar  ' perim
eter = ' pr);
end if;
end;

Enter value for l: 10
old 7: l:=&l;
new 7: l:=10;
Enter value for b: 6
old 8: b:=&b;
new 8: b:=6;
the area is > its perimeter area = 60 perimeter = 32
PL/SQL procedure successfully completed.

P5. WRITE A PROGRAM TO INPUT A SINGLE DIGIT NO: CONVERT IT INTO WORDS.
Declare
a number;
t varchar2(10);
begin
a :=&a;
if a=1 then
http://placementkit.blogspot.com/


t := 'one';
elsif a=2 then
t := 'two';
elsif a= 3 then
t := 'three';
elsif a= then
t := 'four';
elsif a=5 then
t := 'five';
elsif a=6 then
t := 'six';
elsif a=7 then
t := 'seven';
elsif a=8 then
t := 'eight';
elsif a=9 then
t := 'nine';
else
t := 'zero';
end if;
dbms_output.put_line(a     '='     t);
end;

Enter value for a: 2
old 5: a:=&a;
new 5: a:=2;
2 = two
PL/SQL procedure successfully completed.

P6 . Write a program to check the given number is +ve or ve :
SQL>
declare
n number(2):=12;
begin
if n>0 then
dbms_output.put_line('the given number is positive' n);
else
dbms_output.put_line('the given number is negative'  n);
end if;
end;
/

SQL> save posneg.sql
Created file posneg.sql
SQL >The given number is positive 12
PL/SQL procedure successfully completed.
PROGRAM BASED ON NESTED IF LOOP

P7. WRITE A PROGRAM TO INPUT 2 NUMBERS IF THE 1st No >2nd No THEN SWAP
IT, ELSE IF 1st No < 2nd No RAISE IT TO ITS POWER , ELSE DOUBLES IT.
declare
a number(5);
b number(5);
http://placementkit.blogspot.com/


t number(5);
begin
a := &a;
b := &b;
dbms_output.put_line( 'initial value of a = ' a   'b=' b)
if a>b
then
t:= a;
a:= b;
b:=t;
elsIF A<B
then
a:=a**a;
b:=b**b;
ELSE
a:=2*a;
b:=2*b;
end if;
dbms_output.put_line('final value of a = ' a    ' b = ' b);
end;

SQL> /
Enter value for a: 4
old 6: a:=&a;
new 6: a:=4;
Enter value for b: 5
old 7: b:=&b;
new 7: b:=5;
initial value of a = 4 b = 5
final value of a = 256 b = 3125
PL/SQL procedure successfully completed.

SQL> /
Enter value for a: 5
old 6: a:=&a;
new 6: a:=5;
Enter value for b: 4
old 7: b:=&b;
new 7: b:=4;
initial value of a = 5 b = 4
final value of a = 4 b = 5
PL/SQL procedure successfully completed.

SQL> Enter value for a: 5
old 6: a:=&a;
new 6: a:=5;
Enter value for b: 5
old 7: b:=&b;
new 7: b:=5;
initial value of a = 5 b = 5
final value of a = 10 b = 10
PL/SQL procedure successfully completed.
P8. A bank accepts fixed deposits for one or more years and the policy it ad
http://placementkit.blogspot.com/


opts on interest is as follows:
If a deposit is < Rs 2000 and for 2 or more years , the interest rat
e is 5% compounded annually.
If a deposit is Rs.2000 or more but less than 6000 and for 2 or more
years , the interest is 7 % compounded annually.
If a deposit is Rs.6000 and for 1 or more years , the interest is 8
% compounded annually.
On all deposits for 5 years or more , interest is 10% compounded ann
ually.
On all other deposits not covered by above conditions , the interest
is 3% compounded annually.
Given the amount deposited and the number of years , Write a program to calc
ulate the amount on maturity.
declare
p number(9,2);
r number(9,2);
t number(9,2);
ci number(9,2);
begin
p := &p;
t := &t;
if p<2000 and t>=2 then
r := 5;
elsif p>=2000 and p<6000 and t>=2 then
r := 7;
elsif p>6000 and t>=1 then
r := 8;
elsif t>=5 then
r := 10;
else
r := 3;
end if;
ci := p*(1+r/100)**t - p;
dbms_output.put_line('The Principal amount is ='      p);
dbms_output.put_line('The rate of interest is =' r);
dbms_output.put_line('The time period is =' t);
dbms_output.put_line('The compund interst is =' ci);
end;

Enter value for p: 10000
old 7: p:=&p;
new 7: p:=10000;
Enter value for t: 5
old 8: t:=&t;
new 8: t:=5;
The Principal amount is =10000
The rate of interest is =8
The time period is =5
The compund interst is =4693.28
PL/SQL procedure successfully completed.


Enter value for p: 1500
http://placementkit.blogspot.com/


old 7: p:=&p;
new 7: p:=1500;
Enter value for t: 3
old 8: t:=&t;
new 8: t:=3;
The Principal amount is =1500
The rate of interest is =5
The time period is =3
The compound interest is =236.44
PL/SQL procedure successfully completed.

P9. WRITE A PROGRM TO INPUT 3 NUMBERS FIND THE 1st Greatest, 2nd Greatest,
3rd Greatest.
declare
a number(3);
b number(3);
c number(3);
f number(3);
s number(3);
t number(3);
begin
a :=&a;
b :=&b;
c :=&c;
if a>b and a>c then
f:= a;
if b>c then
s:=b;
t:=c;
else
s:=c;
t:=b;
end if;
elsif b>a and b>c then
f:= b;
if a>c then
s:=a;
t:=c;
else
s:=c;
t:=a;
end if;
else
f:= c;
if a>b then
s:=a;
t:=b;
else
s:=b;
t:=a;
end if;
end if;
dbms_output.put_line('first largest = ' f);
http://placementkit.blogspot.com/


dbms_output.put_line('second largest = '    s);
dbms_output.put_line('third largest = '  t);
end;
/

Enter value for a: 5
old 9: a:=&a;
new 9: a:=5;
Enter value for b: 8
old 10: b:=&b;
new 10: b:=8;
Enter value for c: 9
old 11: c:=&c;
new 11: c:=9;
first largest = 9
second largest = 8
third largest = 5
PL/SQL procedure successfully completed.

P10 . WRITE A PROGRAM TO INPUT 2 NUMBERS AND AN OPERATOR , AND
DISPLAY THE RESULT.
declare
a number(3) ;
b number(3) ;
c number(3) ;
op char(1) ;
begin
a := &a ;
b := &b ;
op := &op ;
if op='+'
then
c:=a+b;
elsif op='-'
then
c:=a-b;
elsif op='*'
then
c:=a*b;
else
c:=a/b;
end if;
dbms_output.put_line('result=' c);
end;

Enter value for a: 5
old 7: a:=&a;
new 7: a:=5;
Enter value for b: 6
old 8: b:=&b;
new 8: b:=6;
Enter value for op: '*'
old 9: op:=&op;
http://placementkit.blogspot.com/


new 9: op:='*';
result=30
PL/SQL procedure successfully completed.

P11. Write a program to calculate the commission of the sales man.
If salesmade Comm
>10000 500
10000 20000 1000
>20000 1500
declare
sman varchar(10);
sm number(9,2);
com number(9,2);
begin
sman := &sman;
sm := &sm;
if sm > 10000 then
com := 500;
elsif sm > 20000 then
com := 1000;
else
com := 1500;
end if;
dbms_output.put_line(' the sales man name is :' sman);
dbms_output.put_line(' the sales made is :' sm);
dbms_output.put_line(' the sales commission is :' com);
end;

Enter value for sman: 'Mathew'
old 6: sman:=&sman;
new 6: sman:='Mathew';
Enter value for sm: 15000
old 7: sm:=&sm;
new 7: sm:=15000;
The sales man name is :Mathew
The sales made is :15000
The sales commission is :500
PL/SQL procedure successfully completed.
PROGRAM BASED ON WHILE LOOP

P12. TO GENERATE NUMBERS FROM 0 TO 25 IN STEP OF 5
declare
i number :=10 ;
begin
dbms_output.put_line(' THE WHILE LOOP begins');
WHILE I<=25 LOOP
dbms_output.put_line(to_char(i));
i:=i+5;
end loop;
End;
THE WHILE LOOP BEGINS
10
15
http://placementkit.blogspot.com/


20
25
PL/SQL procedure successfully completed.

P13. Write a program to find the sum of the digits of the number:
DECLARE
N number ;
S NUMBER :=0;
R NUMBER;
begin
n:=&N;
WHILE N<>0 LOOP
R := MOD(N,10);
S := S + R;
N := TRUNC(N/10);
end loop;
dbms_output.put_line('THE SUM OF THE DIGITS = '    S);
end;
SQL> Enter value for n: 375
old 7: n:=&N;
new 7: n:=375;
THE SUM OF THE DIGITS = 15
PL/SQL procedure successfully completed.
PROGRAM BASED ON NESTED WHILE LOOP
PROGRAM BASED ON FOR LOOP

P14. WRITE A PROGRAM CODE TO PRINT THE MULTIPLICATION TABLE OF A GIVEN
NO:
declare
t number(3) := 3;
begin
T := &T;
FOR I IN 1..3 LOOP
dbms_output.put_line(t 'X' i '='   i*t );
end loop;
end;

p15. write aprogram to generate even numbers from 2 to 50, and find its sum.
declare
i number(5);
n number(5);
v number(5);
s number(5):=0;
begin
n := &terminal_number;
for i in 1 .. n/2 loop
v := i*2;
s := s+v;
dbms_output.put_line(v);
end loop;
dbms_output.put_line('the sum of numbers from 2 to ' n ' = ' s);
end;
SQL> /
http://placementkit.blogspot.com/


Enter value for terminal_number: 10
old 7: n:=&terminal_number;
new 7: n:=10;
2
4
6
8
10
The sum of numbers from 2 to 10 = 30
PL/SQL procedure successfully completed.

P16 . WRITE A PROGRAM TO GENERATE FIRST 25 TERMS OF THE FIBONACCIS
SERIES.
declare
a number:= 0 ;
b number:= 1;
c number;
begin
dbms_output.put(a ' ' b ' ');
for i in 3..10 loop
c := a + b;
dbms_output.put(c ' ');
a := b;
b := c;
end loop;
dbms_output.put_line(' ');
end;
0 1 1 2 3 5 8 13 21 34
PL/SQL procedure successfully completed.

P17. Write a program to find the factorial of a number :
declare
n number(2);
i number(2);
f number(5):=1;
begin
n :=&n;
for i in 1..n loop
f := f * i;
end loop;
dbms_output.put_line(' the factorial value = ' f);
end;
Enter value for n: 5
old 6: n:=&n;
new 6: n:=5;
the factorial value = 120
PROGRAM BASED ON NESTED FOR LOOP




P18. Write a program to print the following design:
http://placementkit.blogspot.com/


1
12
123
1234
12345
declare
i number ;
j number;
n number;
begin
n :=&n;
for i in 1..n loop
for j in 1..i loop
dbms_output.put(j);
end loop;
dbms_output.put_line(' ');
end loop;
end;
Enter value for n: 5
old 6: n:=&n;
new 6: n:=5;

P19. WRITE A PROGRAM TO DISPLAY NUMBERS OF THE FORM
00000
12345
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
DECLARE
I NUMBER;
J NUMBER ;
K NUMBER;
BEGIN
FOR I IN 0 .. 5 LOOP
FOR J IN 1..5 LOOP
K := I*J;
DBMS_OUTPUT.PUT(K);
END LOOP;
DBMS_OUTPUT. PUT_LINE (' ');
END LOOP;
END;

P20. WRITE A PL/SQL CODE TO ACCEPT THE TEXT AND REVERSE THE GIVEN TEXT.
CHECK THE TEXT IS PALINDROME OR NOT
DECLARE
G VARchar2(20);
r VARchar2(20);
BEGIN
G:='&g';
dbms_output.put_line('THE GIVEN TEXT :' G);
for i in REVERSE 1.. length(G) loop
R:= R substr(G,i,1);
http://placementkit.blogspot.com/


end loop;
dbms_output.put_line('THE REVERSED TEXT :' R);
IF R=G THEN
dbms_output.put_line('THE GIVEN TEXT IS PALINDROME ');
ELSE
dbms_output.put_line('THE GIVEN TEXT IS NOT PALINDROME ');
END IF;
end;
SQL> /
Enter value for g: MALAYALAM
old 5: G:='&g';
new 5: G:='MALAYALAM';
THE GIVEN TEXT :MALAYALAM
THE REVERSED TEXT :MALAYALAM
THE GIVEN TEXT IS PALINDROME
PL/SQL procedure successfully completed.
/
Enter value for g: HELLO
old 5: G:='&g';
new 5: G:='HELLO';
THE GIVEN TEXT :HELLO
THE REVERSED TEXT :OLLEH
THE GIVEN TEXT IS NOT PALINDROME
PL/SQL procedure successfully completed.

P21. Write a program to print the following design:
declare
i number ;
j number;
n number;
k number;
m number;
begin
n := &n;
for i in 1..n loop
for j in 1..n-i loop
dbms_output.put('~');
end loop;
for k in 1..i loop
dbms_output.put(k);
end loop;
for k in reverse 1..i-1 loop
dbms_output.put(k);
end loop;
dbms_output.put_line(' ');
end loop;
end;
Enter value for n: 5
old 8: n:=&n;
new 8: n:=5;
~~~~1
~~~121
~~12321
http://placementkit.blogspot.com/


~1234321
123454321
PL/SQL procedure successfully completed.

P22. Write a program to print the following design :
declare
i number ;
j number;
n number;
k number;
m number;
begin
n := &n;
for i in 1..n loop
for j in 1..n-i loop
dbms_output.put('~');
end loop;
for k in 1..i loop
dbms_output.put(k);
end loop;
for k in reverse 1..i-1 loop
dbms_output.put(k);
end loop;
dbms_output.put_line(' ');
end loop;
for i in reverse 1..n-1 loop
for j in 1..n-i loop
dbms_output.put('~');
end loop;
for k in 1..i loop
dbms_output.put(k);
end loop;
for k in reverse 1. . i-1 loop
dbms_output.put(k);
end loop;
dbms_output.put_line(' ');
end loop;
end;
Enter value for n: 5
old 8: n:=&n;
new 8: n:=5;
~~~~1
~~~121
~~12321
~1234321
123454321
~1234321
~~12321
~~~121
~~~~1
PL/SQL procedure successfully completed.
PROGRAM BASED ON FOR & IF
P23. GENERATE ODD NOS: FROM 1 TO 10 AND FIND ITS SUM.
http://placementkit.blogspot.com/


DECLARE
I NUMBER(4);
S NUMBER(4):=0;
BEGIN
FOR I IN 1..10 LOOP
IF MOD(I,2) <> 0 THEN
S := S+I;
DBMS_OUTPUT.PUT_LINE(I);
END IF;
END LOOP;
DBMS_OUTPUT.PUT_LINE(' THE SUM OF ODD NOS FROM 1 TO 10 = '     S);
END;
SQL>/
1
3
5
7
9
THE SUM OF ODD NOS FROM 1 TO 10 = 25
PL/SQL procedure successfully completed.

P24 . WRITE A PROGRAM TO ALL ODD NUMBERS FORM 10 TO 1 IN REVERSE
ORDER.
declare
i number(5);
n number(5);
v number(5);
s number(5) :=0;
begin
S := &STARTING_NUMBER;
n := &terminal_number;
for i in REVERSE S .. N loop
IF MOD (I,2) <>0 THEN
s := s + I;
dbms_output.put_line(I);
end loop;
dbms_output.put_line('the sum of numbers from 2 to ' n ' = ' s);
end;
Enter value for starting number : 1
Old 6: s=&starting_number:1
New 6: s:=1;
Enter value for Terminal_number: 10
old 7: n := &terminal_number;
new 7: n:=10;
9
7
5
3
1
The sum of numbers from 1 to 9 = 25
PL / SQL procedure successfully completed.

P25. Write a program to check the given no: is prime or not:
http://placementkit.blogspot.com/


declare
n number;
i number;
pr number(2):=1;
begin
n:= &n;
for i in 2..n/2 loop
if mod(n,i) = 0 then
pr := 0;
end if;
end loop;
if pr = 1 then
dbms_output.put_line(' the given no: is prime: ' n);
else
dbms_output.put_line(' the given no: is not prime: ' n);
end if;
end;
Enter value for n: 7
old 6: n:=&n;
new 6: n:=7;
the given no: is prime: 7
PL/SQL procedure successfully completed.
SQL> /
Enter value for n: 25
old 6: n:=&n;
new 6: n:=25;
the given no: is not prime: 25
PL/SQL procedure successfully completed.

P26. WRITE A PROGRAM TO PRINT ASCII TABLE :
DECLARE
I NUMBER;
BEGIN
FOR I IN 33..256 LOOP
DBMS_OUTPUT.PUT (( TO_CHAR (I,'000'))       ':' CHR(I)           ' ' );
IF MOD (I, 8) = 0 THEN
DBMS_OUTPUT.PUT_LINE(' ');
END IF;
END LOOP;
END;
033:! 034:" 035:# 036:$ 037:% 038:& 039:' 040:(
041:) 042:* 043:+ 044:, 045:- 046:. 047:/ 048:0
049:1 050:2 051:3 052:4 053:5 054:6 055:7 056:8
249:ù 250:ú 251:û 252:ü 253:ý 254:þ 255:ÿ 256:
:: :: :: :: :: ::
:: :: :: :: :: ::
PL/SQL procedure successfully completed.




P27. Write a program to generate prime nos from 1 to 10:
http://placementkit.blogspot.com/


declare
n number;
i number;
pr number;
begin
for n in 1..10 loop
pr:=1;
for i in 2 .. n/2 loop
if mod(n,i) = 0 then
pr := 0;
end if;
end loop;
if pr = 1 then
dbms_output.put_line(n);
end if;
end loop;
end;
1
2
3
5
7

P28 . Write a program to check the square root of a number is prime or not.
declare
n number;
i number;
pr number;
begin
pr := 1;
n := &n;
n := sqrt(n);
for i in 2 .. n/2 loop
if mod(n,i) = 0 then
pr := 0;
end if;
end loop;
if pr = 1 then
dbms_output.put_line('the square root of the given number is prime' n*n);
else
dbms_output.put_line('the square root of the given number is not prime' n*n
);
end if;
end;
SQL> Enter value for n: 81
old 7: n:=&n;
new 7: n:=81;
The square root of the given number is not prime81
PL/SQL procedure successfully completed.
PROGRAM BASED ON LOOP... END LOOP


P29. Write a program to reverse the digits of the number:
http://placementkit.blogspot.com/


DECLARE
N number ;
S NUMBER : = 0;
R NUMBER;
K number;
begin
N := &N;
K := N;
LOOP
EXIT WHEN N = 0 ;
S := S * 10;
R := MOD(N,10);
S := S + R;
N := TRUNC(N/10);
end loop;
dbms_output.put_line( ' THE REVERSED DIGITS '       ' OF '      K   '='   S);
end;
Enter value for n: 4567
old 7: N:=&N;
new 7: N:=4567;
THE REVERSED DIGITS OF 4567 = 7654
PL/SQL procedure successfully completed.
PROGRAM BASED ON RECORDS

P30. WRITE PL/SQL SCRIPT TO CREATE A RECORD TYPE THAT CAN HOLD SALES IN
4 DIFFERENT QUARTERS.
Structure of the table :
SALES ( SNO, NAME, QUAD1, QUAD2, QUAD3, QUAD4 )
SALES2004 ( Q1, Q2, Q3, Q4 )
DECLARE
TYPE SALEREC IS RECORD
( Q1 NUMBER,
Q2 NUMBER,
Q3 NUMBER,
Q4 NUMBER,
);
BEGIN
SREC SALEREC ;
SELECT SUM(QUAD1) , SUM(QUAD2) , SUM(QUAD3), SUM(QUAD4) INTO SREC FROM
SALES
;
INSERT INTO SALES2004 VALUES (SREC.Q1 ,SREC.Q2, SREC.Q3, SREC.Q4);
END;
PROGRAM BASED ON DATABASE INTERACTION

P31 . Write PL/SQL SCRIPT to determine the salary of employee in the EMP tab
le. If salary >7500 give an increment of 15% , otherwise display the message NO
INCREMENT . Get the empno from the user.
DECLARE
ENO EMP.EMPNO%TYPE;
SALARY EMP.SAL%TYPE;
BEGIN
ENO := &ENO;
http://placementkit.blogspot.com/


SELECT SAL INTO SALARY FROM EMP WHERE EMPNO=ENO;
IF SALARY >7500 THEN
UPDATE EMP SET SAL =SAL+SAL* 15/100 WHERE EMPNO=ENO;
ELSE
DBMS_OUTPUT.PUT_LINE(NO INCREMENT)
END IF;
END;

P32 . GIVEN A TABLE STUDENT ( SID INTEGER PRIMARY KEY, NAME CHAR(30),
AGE INTEGER , GPA FLOAT ). WRITE A PL/SQL SCRIPT TO GO THROUGH SID 142-
857 AND SET ALL GPA UNDER 4.0 TO 4.0 .
DECLARE
TSID STUDENT.SID%TYPE;
TGPA STUDENT.GPA%TYPE;
BEGIN
TSID:=142;
LOOP
EXIT WHEN TSID > 857 ;
SELECT GPA INTO TGPA FROM STUDENT WHERE SID=TSID;
IF TGPA< 4.0 THEN
UPDATE STUDENT SET GPA=4.0 WHERE SID=TSID;
END IF;
TSID:=TSID+1;
END LOOP;
END;

P33 . DISPLAY AVERAGE SALARY , TOTOL NO: OF EMP, AND TOTAL SALARY FOR
FIRST 5 DEPARTMENTS IN EMP TABLE. DEPT NO ARE 10,20,30,40,5090.
DECLARE
DNO NUMBER:=10;
DPNAME DEPT. DNAME%TYPE;
ASAL EMP. SAL%TYPE;
ACOUNT NUMBER;
SSAL EMP. SAL%TYPE;
BEGIN
LOOP
EXIT WHEN DNO > 50;
SELECT DNAME INTO DPNAME FROM DEPT WHERE DEPTNO=DNO;
SELECT AVG(SAL), COUNT(*), SUM(SAL) INTO ASAL, ACOUNT,SSAL
FROM EMP WHERE DEPTNO = DNO;
DBMS_OUTPUT.PUT_LINE( DEPARTMENT NAME        DPNAME);
DBMS_OUTPUT.PUT_LINE( DEPARTMENT COUNT        ACOUNT);
DBMS_OUTPUT.PUT_LINE( AVERAGE SALARY      ASAL);
DBMS_OUTPUT.PUT_LINE( SUM SALARY      SSAL);
DNO := DNO+10;
END LOOP;
END;
http://placementkit.blogspot.com/


P34. WRITE A PL/SQL SCRIPT TO COUNT THE NO: OF EMPLOYEES. IF TOTAL <10
DISPLAY SMALL COMPANY, ELSE IF TOTAL BETWEEN 10-50 DISPLAY MEDIUM
ELSE DISPLAY LARGE
.
DECLARE
TOT NUMBER (3);
BEGIN
SELECT COUNT(*) INTO TOT FROM EMP;
IF TOT <10 THEN
TEXT := SMALL ;
ELSIF TOT<50 THEN
TEXT := MEDIUM;
ELSE
TEXT := LARGE;
END IF;
DBMS_OUTPUT.PUT_LINE( TEXT     COMPANY);
END;

P35. Find the employee drawing minimum salary. Add his details like empno, n
ame, sal into the table newsal, after incrementing Rs.700.
DECLARE
ENO EMP.EMPNO%TYPE;
NAME EMP.ENAME%TYPE;
SALARY EMP.SAL%TYPE;
BEGIN
SELECT EMPNO, ENAME, SAL INTO ENO, NAME, SALARY
FROM EMP WHERE SAL = (SELECT MIN(SAL) FROM EMP);
SALARY := SALARY+700;
INSERT INTO NEWSAL VALUES ( ENO,NAME,SALARY);
END;

P36. Write a program to update the salary of the employee by 25% if he earns
salary >4000, otherwise if salary <4000 update by 10%, else update by 15%.
DECLARE
S NUMBER(8,2) ;
NAME VARCHAR2(10);
BEGIN
NAME:=&NAME;
SELECT SAL INTO S FROM EMP WHERE ENAME = NAME;
IF S >4000 THEN
UPDATE EMP SET SAL := SAL+SAL*20/100 WHERE ENAME=NAME;
ELSIF S<4000
UPDATE EMP SET SAL := SAL+SAL*10/100 WHERE ENAME=NAME;
ELSE
UPDATE EMP SET SAL := SAL+SAL*15/100 WHERE ENAME=NAME;
END IF;
END;

P37 .Write PL/SQL code to increase the sal of an employee by 5% whose salary
is more than 4000 . Get the empno from the user.
DECLARE
ENO NUMBER(4);
BEGIN
http://placementkit.blogspot.com/


ENO := &ENO;
UPDATE EMP SET SAL =SAL+SAL*5/100 WHERE SAL>4000 AND EMPNO=ENO;
END;

P38. GIVEN A TABLE TEMP ( SNO NUMBER(3) , DNO NUMBER,TEXT CHAR (4) .
WRITE A
PL/SQL SCRIPT TO INSERT 10 RECORDS IN TABLE TEMP AS PER THE FOLLOWING
SPECIFICA
TIONS:
SNO DNO TEXT
1 50 ODD
2 100 EVEN
3 150 ODD
DECLARE
SNO NUMBER := 1;
DNO NUMBER ;
TEXT CHAR(5) ;
BEGIN
LOOP
EXIT WHEN SNO > 10;
DNO := SNO * 50;
IF MOD ( SNO, 2 ) = 0
TEXT := EVEN;
ELSE
TEXT := ODD;
INSERT INTO TEMP VALUES (SNO,DNO,TEXT);
SNO := SNO + 1;
END LOOP;
COMMIT;
END;

P39 . Write PL/SQL code to DELETE the record of an employee whose salary is
more than 4000 . Get the empno from the user.
DECLARE
ENO NUMBER(4);
BEGIN
ENO := &ENO;
DELETE FROM EMP WHERE SAL>4000 AND EMPNO=ENO;
END;

P40 .Write PL/SQL code to insert a new record in the table emp after obtaining
values ( empno, ename, hiredate, sal ) from user.
declare
tempno number(4);
tename varchar(10);
thiredate varchar2(12);
tsal number(7,2);
begin
tempno :=&tempno;
tename :='&tename';
thiredate :='&thiredate';
tsal := &tsal;
insert into emp (empno,ename,hiredate,sal) values(tempno,tename,to_date(thir
http://placementkit.blogspot.com/


edate,'DD-mon-yyyy'),tsal);
end;
Enter value for tempno: 8000
old 7: tempno:=&tempno;
new 7: tempno:=8000;
Enter value for tename: mathew
old 8: tename :='&tename';
new 8: tename :='mathew';
Enter value for thiredate: 10-jan-2004
old 9: thiredate :='&thiredate';
new 9: thiredate :='10-jan-2004';
Enter value for tsal: 8000
old 10: tsal := &tsal;
new 10: tsal := 8000;
PL/SQL procedure successfully completed.

P41. WRITE A PROGRAM TO CREATE A EMP %ROWTYPE RECORD .ACCEPT THE
EMPNO FROM
THE USER, AND DISPLAY ALL THE INFORMATION ABOUT THE EMPLOYEE.
declare
erec emp%rowtype;
eno emp.empno%type;
begin
eno := &eno;
select * into erec from emp where empno=eno;
dbms_output.put_line( 'Emp no : ' erec.empno) ;
dbms_output.put_line( 'Name : ' erec.ename) ;
dbms_output.put_line( 'Salary : ' erec.sal);
dbms_output.put_line( 'Deptno : ' erec.deptno);
dbms_output.put_line( 'hiredate: ' erec.hiredate);
dbms_output.put_line( 'job : ' erec.job);
end;
SQL> /
Enter value for eno: 7788
old 5: eno := &eno;
new 5: eno := 7788;
Emp no : 7788
Name : SCOTT
Salary : 1452
Deptno : 20
hiredate: 19-APR-87
job : ANALYST
PL/SQL procedure successfully completed.
PROGRAM BASED ON EXCEPTION

P42. Write PL/SQL script that traps an invalid data type value given and displays a
custom error message.
DECLARE
ENO EMP. EMPNO%TYPE;
SNO VARCHAR2(5);
NAME EMP.ENMAE%TYPE;
BEGIN
SNO := &SNO ;
http://placementkit.blogspot.com/


SELECT EMPNO,ENAME INTO ENO,NAME FROM EMP WHERE EMPNO=SNO;
DBMS_OUTPUT.PUT_LINE ( NAME     ENAME    EMPNO    EMPNO);
EXCEPTION
WHEN INVALID_NUMBER THEN
DBMS_OUTPUT.PUT_LINE(SNO    IS INVALID DATA FOR EMPLOYEE ID);
END;
PROGRAM BASED ON FUNCTIONS

P43 . write a function to create factorial of a number.
CREATE OR REPLACE FUNCTION FACT (N NUMBER)
RETURN NUMBER
IS
I NUMBER(10);
F NUMBER :=1;
BEGIN
FOR I IN 1.. N LOOP
F:= F*I;
END LOOP;
RETURN F;
END;
SQL> /
Function created.
SQL> select fact(8) from dual;
FACT(8)
---------
40320
PROGRAM BASED ON PROCEDURES

P44. Write a Procedure to increase the salary for all the employees in the EMP
table :
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
--------- ---------- --------- --------- --------- --------- --------- -----
----
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
14 rows selected.
SQL> create or replace procedure inc(i number)
is
begin
update emp set sal =sal+i;
end;
/
Procedure created.
To execute the procedures in the PL/SQL block:
SQL> declare
begin
inc(100);
end;
/
PL/SQL procedure successfully completed.
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
http://placementkit.blogspot.com/


7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1700 300 30
14 rows selected.

P45. WRITE A PROCEDURE TO INCREASE THE SALARY FOR THE SPECIFIED
EMPLOLEE USING EMPNO IN THE EMP TABLE BASED ON THE FOLLOWING
CRITERIA: INCREASE THE SALARY BY 5% FOR CLERKS, 7% FOR SALESMAN , 10%
FOR ANALYST, 20 % FOR MANAGER and 25% FOR PRESIDENT. ACTIVATE USING
PL/SQL BLOCK.
SQL> SELECT * FROM EMP;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPT
7369 SMITH CLERK 7902 17-DEC-80 800 20
CREATE OR REPLACE PROCEDURE DESIGNATION(ENO NUMBER)
IS
BEGIN
UPDATE EMP SET SAL=SAL+SAL*5/100 WHERE JOB ='CLERK' AND EMPNO=ENO;
UPDATE EMP SET SAL=SAL+SAL*7/100 WHERE JOB='SALESMAN' AND EMPNO=ENO;
UPDATE EMP SET SAL=SAL+SAL*10/100 WHERE JOB='ANALYST' AND EMPNO=ENO;
UPDATE EMP SET SAL=SAL+SAL*20/100 WHERE JOB='MANAGER' AND EMPNO=ENO;
UPDATE EMP SET SAL=SAL+SAL*25/100 WHERE JOB='PRESIDENT' AND EMPNO=ENO;
END;
SQL> /
Procedure created.
SQL> DECLARE
2 BEGIN
3 DESIGNATION(7369);
4 END;
5/
PL/SQL procedure successfully completed.
SQL> SELECT * FROM EMP;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPT
7369 SMITH CLERK 7902 17-DEC-80 840 20__

Contenu connexe

Tendances

1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQLrehaniltifat
 
BCD to Decimal - Digital Electronics
BCD to Decimal - Digital ElectronicsBCD to Decimal - Digital Electronics
BCD to Decimal - Digital ElectronicsMilap Bhanderi
 
Number Guessing Game - A 8085 Project
Number Guessing Game - A 8085 ProjectNumber Guessing Game - A 8085 Project
Number Guessing Game - A 8085 ProjectSneh Pahilwani
 
Revised Data Structure- STACK in Python XII CS.pdf
Revised Data Structure- STACK in Python XII CS.pdfRevised Data Structure- STACK in Python XII CS.pdf
Revised Data Structure- STACK in Python XII CS.pdfMohammadImran709594
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL CommandsShrija Madhu
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language BasicsEducation Front
 
Python - gui programming (tkinter)
Python - gui programming (tkinter)Python - gui programming (tkinter)
Python - gui programming (tkinter)Learnbay Datascience
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statementnarmadhakin
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Oum Saokosal
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functionssinhacp
 
Slide 5 keys
Slide 5 keysSlide 5 keys
Slide 5 keysVisakh V
 

Tendances (20)

Floating point arithmetic
Floating point arithmeticFloating point arithmetic
Floating point arithmetic
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
 
BCD to Decimal - Digital Electronics
BCD to Decimal - Digital ElectronicsBCD to Decimal - Digital Electronics
BCD to Decimal - Digital Electronics
 
BCNF
BCNFBCNF
BCNF
 
Adder ppt
Adder pptAdder ppt
Adder ppt
 
Number Guessing Game - A 8085 Project
Number Guessing Game - A 8085 ProjectNumber Guessing Game - A 8085 Project
Number Guessing Game - A 8085 Project
 
Revised Data Structure- STACK in Python XII CS.pdf
Revised Data Structure- STACK in Python XII CS.pdfRevised Data Structure- STACK in Python XII CS.pdf
Revised Data Structure- STACK in Python XII CS.pdf
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
 
Python - gui programming (tkinter)
Python - gui programming (tkinter)Python - gui programming (tkinter)
Python - gui programming (tkinter)
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 
Binary codes
Binary codesBinary codes
Binary codes
 
Linked list
Linked listLinked list
Linked list
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
SQL select clause
SQL select clauseSQL select clause
SQL select clause
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
Slide 5 keys
Slide 5 keysSlide 5 keys
Slide 5 keys
 
What is Gray Code?
What is Gray Code? What is Gray Code?
What is Gray Code?
 

En vedette

Plsql task answers
Plsql task answersPlsql task answers
Plsql task answersNawaz Sk
 
Sql queries interview questions
Sql queries interview questionsSql queries interview questions
Sql queries interview questionsPyadav010186
 
Sql Queries
Sql QueriesSql Queries
Sql Querieswebicon
 
Sql 99 and_some_techniques
Sql 99 and_some_techniquesSql 99 and_some_techniques
Sql 99 and_some_techniquesAlexey Kiselyov
 
Mc amca04919 plsql programs
Mc amca04919 plsql programsMc amca04919 plsql programs
Mc amca04919 plsql programsAshwin Kumar
 
Contract-oriented PLSQL Programming
Contract-oriented PLSQL ProgrammingContract-oriented PLSQL Programming
Contract-oriented PLSQL ProgrammingJohn Beresniewicz
 
Sql task answers
Sql task answersSql task answers
Sql task answersNawaz Sk
 
Oracl DBA lab manual
Oracl DBA lab manualOracl DBA lab manual
Oracl DBA lab manualAbdulla Shaik
 
PLSQL Standards and Best Practices
PLSQL Standards and Best PracticesPLSQL Standards and Best Practices
PLSQL Standards and Best PracticesAlwyn D'Souza
 
Introduction to Machine Learning for Oracle Database Professionals
Introduction to Machine Learning for Oracle Database ProfessionalsIntroduction to Machine Learning for Oracle Database Professionals
Introduction to Machine Learning for Oracle Database ProfessionalsAlex Gorbachev
 
Term Deposit
Term DepositTerm Deposit
Term Depositnishant78
 
Oracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practicesOracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practicesSmitha Padmanabhan
 

En vedette (20)

Plsql task answers
Plsql task answersPlsql task answers
Plsql task answers
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Sql queries interview questions
Sql queries interview questionsSql queries interview questions
Sql queries interview questions
 
Sql Queries
Sql QueriesSql Queries
Sql Queries
 
plsql Lec11
plsql Lec11 plsql Lec11
plsql Lec11
 
Jscript part1
Jscript part1Jscript part1
Jscript part1
 
Sql 99 and_some_techniques
Sql 99 and_some_techniquesSql 99 and_some_techniques
Sql 99 and_some_techniques
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Mc amca04919 plsql programs
Mc amca04919 plsql programsMc amca04919 plsql programs
Mc amca04919 plsql programs
 
Bca
BcaBca
Bca
 
Plsql programs
Plsql programsPlsql programs
Plsql programs
 
Contract-oriented PLSQL Programming
Contract-oriented PLSQL ProgrammingContract-oriented PLSQL Programming
Contract-oriented PLSQL Programming
 
Plsql Ref
Plsql RefPlsql Ref
Plsql Ref
 
Sql task answers
Sql task answersSql task answers
Sql task answers
 
Oracl DBA lab manual
Oracl DBA lab manualOracl DBA lab manual
Oracl DBA lab manual
 
PLSQL Standards and Best Practices
PLSQL Standards and Best PracticesPLSQL Standards and Best Practices
PLSQL Standards and Best Practices
 
Introduction to Machine Learning for Oracle Database Professionals
Introduction to Machine Learning for Oracle Database ProfessionalsIntroduction to Machine Learning for Oracle Database Professionals
Introduction to Machine Learning for Oracle Database Professionals
 
Term Deposit
Term DepositTerm Deposit
Term Deposit
 
Oracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practicesOracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practices
 
Pl lab solution
Pl lab solutionPl lab solution
Pl lab solution
 

Similaire à Plsql programs(encrypted)

PL /SQL program UNIT 5 DMS 22319
PL /SQL program UNIT 5 DMS 22319PL /SQL program UNIT 5 DMS 22319
PL /SQL program UNIT 5 DMS 22319ARVIND SARDAR
 
Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdfYashMirge2
 
Chapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docxChapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docxShamshad
 
c++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfc++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfayush616992
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solutionKuntal Bhowmick
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C LabNeil Mathew
 
C program report tips
C program report tipsC program report tips
C program report tipsHarry Pott
 
LAB_MANUAL_cpl_21scheme-2.pdf
LAB_MANUAL_cpl_21scheme-2.pdfLAB_MANUAL_cpl_21scheme-2.pdf
LAB_MANUAL_cpl_21scheme-2.pdfRavinReddy3
 
Lecture_Activities_4.1_to_4.7.pdf.pdf
Lecture_Activities_4.1_to_4.7.pdf.pdfLecture_Activities_4.1_to_4.7.pdf.pdf
Lecture_Activities_4.1_to_4.7.pdf.pdfNancySantos49
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfMuhammadMaazShaik
 

Similaire à Plsql programs(encrypted) (20)

PL /SQL program UNIT 5 DMS 22319
PL /SQL program UNIT 5 DMS 22319PL /SQL program UNIT 5 DMS 22319
PL /SQL program UNIT 5 DMS 22319
 
5 a4.output
5 a4.output5 a4.output
5 a4.output
 
PLSQL.docx
PLSQL.docxPLSQL.docx
PLSQL.docx
 
Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdf
 
BScPLSQL.pdf
BScPLSQL.pdfBScPLSQL.pdf
BScPLSQL.pdf
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
Chapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docxChapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docx
 
c programing
c programingc programing
c programing
 
C
CC
C
 
c++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfc++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdf
 
I PUC CS Lab_programs
I PUC CS Lab_programsI PUC CS Lab_programs
I PUC CS Lab_programs
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C Lab
 
C program report tips
C program report tipsC program report tips
C program report tips
 
LAB_MANUAL_cpl_21scheme-2.pdf
LAB_MANUAL_cpl_21scheme-2.pdfLAB_MANUAL_cpl_21scheme-2.pdf
LAB_MANUAL_cpl_21scheme-2.pdf
 
LMmanual.pdf
LMmanual.pdfLMmanual.pdf
LMmanual.pdf
 
C Programming
C ProgrammingC Programming
C Programming
 
Hargun
HargunHargun
Hargun
 
Lecture_Activities_4.1_to_4.7.pdf.pdf
Lecture_Activities_4.1_to_4.7.pdf.pdfLecture_Activities_4.1_to_4.7.pdf.pdf
Lecture_Activities_4.1_to_4.7.pdf.pdf
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdf
 

Plus de Karunakar Singh Thakur (14)

Rational Team Concert (RTC) installation and setup guide
Rational Team Concert (RTC) installation and setup guideRational Team Concert (RTC) installation and setup guide
Rational Team Concert (RTC) installation and setup guide
 
All About Jazz Team Server Technology
All About Jazz Team Server TechnologyAll About Jazz Team Server Technology
All About Jazz Team Server Technology
 
Android Firewall project
Android Firewall projectAndroid Firewall project
Android Firewall project
 
Hyper Threading technology
Hyper Threading technologyHyper Threading technology
Hyper Threading technology
 
Advanced sql injection 2
Advanced sql injection 2Advanced sql injection 2
Advanced sql injection 2
 
Advanced sql injection 1
Advanced sql injection 1Advanced sql injection 1
Advanced sql injection 1
 
Complete placement guide(non technical)
Complete placement guide(non technical)Complete placement guide(non technical)
Complete placement guide(non technical)
 
Complete placement guide(technical)
Complete placement guide(technical)Complete placement guide(technical)
Complete placement guide(technical)
 
How to answer the 64 toughest interview questions
How to answer the 64 toughest interview questionsHow to answer the 64 toughest interview questions
How to answer the 64 toughest interview questions
 
genetic algorithms-artificial intelligence
 genetic algorithms-artificial intelligence genetic algorithms-artificial intelligence
genetic algorithms-artificial intelligence
 
Hadoop
HadoopHadoop
Hadoop
 
Prepare for aptitude test
Prepare for aptitude testPrepare for aptitude test
Prepare for aptitude test
 
Thesis of SNS
Thesis of SNSThesis of SNS
Thesis of SNS
 
Network survivability karunakar
Network survivability karunakarNetwork survivability karunakar
Network survivability karunakar
 

Dernier

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 

Dernier (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 

Plsql programs(encrypted)

  • 1. http://placementkit.blogspot.com/ PL / SQL PROGRAMS P1. WRITE A NESTED PROGRAM TO ADD AND TO MULTIPLY TWO NUMBERS. DECLARE N1 number; N2 number; Sum number ; BEGIN Sum := N1+N2 ; << inner_block >> DECLARE Prod number; BEGIN Prod := N1 * N2 ; Dbms_output.put_line( Product Value = prod ); END inner_block ; Dbms_output.put_line( Sum Value = sum); END; P2. WRITE A PROGRAM TO CALCULATE THE SIMPLE INTEREST AND COMPUND INTEREST , IF P, N, R ARE GIVEN. declare p number(9,2) ; n number(9,2) ; r number(9,2) ; si number(9,2) := 0; ci number(9,2) := 0; begin p := &principal_amount; n := &no_of_years; r := &rate_of_interest; si := p*n*r/100; ci := p*(1+r/100)**n; dbms_output.put_line('simple interset =' si); dbms_output.put_line('compound interset =' ci); end; SQL> / Enter value for principal_amount: 10000 old 8: p:=&principal_amount; new 8: p:=10000; Enter value for no_of_years: 5 old 9: n:=&no_of_years; new 9: n:=5; Enter value for rate_of_interest: 10.5 old 10: r:=&rate_of_interest; new 10: r:=10.5; simple interset =5250 compound interset =16474.47 PL/SQL procedure successfully completed. PROGRAM BASED ON IF LOOP
  • 2. http://placementkit.blogspot.com/ P3 . Write a program to check greatest of two numbers : declare a number(3) :=20; b number(3) :=10; begin if a>b then dbms_output.put_line('a is the greatest : ' a); else dbms_output.put_line('B is the greatest : ' b); end if; end; SQL> / a is the greatest : 20 PL/SQL procedure successfully completed. P4. Given 2 sides of a rectangle .Write a program to find out its area is gr eater than its perimeter or not . declare l number; b number; ar number; pr number; begin l := &l; b := &b; ar := l*b; pr := 2*(l+b); if ar > pr then dbms_output.put_line('the area iS > its perimeter' 'area = ' ar 'perimet er = ' pr); else dbms_output.put_line('the area iS < its perimeter' ' area = ' ar ' perim eter = ' pr); end if; end; Enter value for l: 10 old 7: l:=&l; new 7: l:=10; Enter value for b: 6 old 8: b:=&b; new 8: b:=6; the area is > its perimeter area = 60 perimeter = 32 PL/SQL procedure successfully completed. P5. WRITE A PROGRAM TO INPUT A SINGLE DIGIT NO: CONVERT IT INTO WORDS. Declare a number; t varchar2(10); begin a :=&a; if a=1 then
  • 3. http://placementkit.blogspot.com/ t := 'one'; elsif a=2 then t := 'two'; elsif a= 3 then t := 'three'; elsif a= then t := 'four'; elsif a=5 then t := 'five'; elsif a=6 then t := 'six'; elsif a=7 then t := 'seven'; elsif a=8 then t := 'eight'; elsif a=9 then t := 'nine'; else t := 'zero'; end if; dbms_output.put_line(a '=' t); end; Enter value for a: 2 old 5: a:=&a; new 5: a:=2; 2 = two PL/SQL procedure successfully completed. P6 . Write a program to check the given number is +ve or ve : SQL> declare n number(2):=12; begin if n>0 then dbms_output.put_line('the given number is positive' n); else dbms_output.put_line('the given number is negative' n); end if; end; / SQL> save posneg.sql Created file posneg.sql SQL >The given number is positive 12 PL/SQL procedure successfully completed. PROGRAM BASED ON NESTED IF LOOP P7. WRITE A PROGRAM TO INPUT 2 NUMBERS IF THE 1st No >2nd No THEN SWAP IT, ELSE IF 1st No < 2nd No RAISE IT TO ITS POWER , ELSE DOUBLES IT. declare a number(5); b number(5);
  • 4. http://placementkit.blogspot.com/ t number(5); begin a := &a; b := &b; dbms_output.put_line( 'initial value of a = ' a 'b=' b) if a>b then t:= a; a:= b; b:=t; elsIF A<B then a:=a**a; b:=b**b; ELSE a:=2*a; b:=2*b; end if; dbms_output.put_line('final value of a = ' a ' b = ' b); end; SQL> / Enter value for a: 4 old 6: a:=&a; new 6: a:=4; Enter value for b: 5 old 7: b:=&b; new 7: b:=5; initial value of a = 4 b = 5 final value of a = 256 b = 3125 PL/SQL procedure successfully completed. SQL> / Enter value for a: 5 old 6: a:=&a; new 6: a:=5; Enter value for b: 4 old 7: b:=&b; new 7: b:=4; initial value of a = 5 b = 4 final value of a = 4 b = 5 PL/SQL procedure successfully completed. SQL> Enter value for a: 5 old 6: a:=&a; new 6: a:=5; Enter value for b: 5 old 7: b:=&b; new 7: b:=5; initial value of a = 5 b = 5 final value of a = 10 b = 10 PL/SQL procedure successfully completed. P8. A bank accepts fixed deposits for one or more years and the policy it ad
  • 5. http://placementkit.blogspot.com/ opts on interest is as follows: If a deposit is < Rs 2000 and for 2 or more years , the interest rat e is 5% compounded annually. If a deposit is Rs.2000 or more but less than 6000 and for 2 or more years , the interest is 7 % compounded annually. If a deposit is Rs.6000 and for 1 or more years , the interest is 8 % compounded annually. On all deposits for 5 years or more , interest is 10% compounded ann ually. On all other deposits not covered by above conditions , the interest is 3% compounded annually. Given the amount deposited and the number of years , Write a program to calc ulate the amount on maturity. declare p number(9,2); r number(9,2); t number(9,2); ci number(9,2); begin p := &p; t := &t; if p<2000 and t>=2 then r := 5; elsif p>=2000 and p<6000 and t>=2 then r := 7; elsif p>6000 and t>=1 then r := 8; elsif t>=5 then r := 10; else r := 3; end if; ci := p*(1+r/100)**t - p; dbms_output.put_line('The Principal amount is =' p); dbms_output.put_line('The rate of interest is =' r); dbms_output.put_line('The time period is =' t); dbms_output.put_line('The compund interst is =' ci); end; Enter value for p: 10000 old 7: p:=&p; new 7: p:=10000; Enter value for t: 5 old 8: t:=&t; new 8: t:=5; The Principal amount is =10000 The rate of interest is =8 The time period is =5 The compund interst is =4693.28 PL/SQL procedure successfully completed. Enter value for p: 1500
  • 6. http://placementkit.blogspot.com/ old 7: p:=&p; new 7: p:=1500; Enter value for t: 3 old 8: t:=&t; new 8: t:=3; The Principal amount is =1500 The rate of interest is =5 The time period is =3 The compound interest is =236.44 PL/SQL procedure successfully completed. P9. WRITE A PROGRM TO INPUT 3 NUMBERS FIND THE 1st Greatest, 2nd Greatest, 3rd Greatest. declare a number(3); b number(3); c number(3); f number(3); s number(3); t number(3); begin a :=&a; b :=&b; c :=&c; if a>b and a>c then f:= a; if b>c then s:=b; t:=c; else s:=c; t:=b; end if; elsif b>a and b>c then f:= b; if a>c then s:=a; t:=c; else s:=c; t:=a; end if; else f:= c; if a>b then s:=a; t:=b; else s:=b; t:=a; end if; end if; dbms_output.put_line('first largest = ' f);
  • 7. http://placementkit.blogspot.com/ dbms_output.put_line('second largest = ' s); dbms_output.put_line('third largest = ' t); end; / Enter value for a: 5 old 9: a:=&a; new 9: a:=5; Enter value for b: 8 old 10: b:=&b; new 10: b:=8; Enter value for c: 9 old 11: c:=&c; new 11: c:=9; first largest = 9 second largest = 8 third largest = 5 PL/SQL procedure successfully completed. P10 . WRITE A PROGRAM TO INPUT 2 NUMBERS AND AN OPERATOR , AND DISPLAY THE RESULT. declare a number(3) ; b number(3) ; c number(3) ; op char(1) ; begin a := &a ; b := &b ; op := &op ; if op='+' then c:=a+b; elsif op='-' then c:=a-b; elsif op='*' then c:=a*b; else c:=a/b; end if; dbms_output.put_line('result=' c); end; Enter value for a: 5 old 7: a:=&a; new 7: a:=5; Enter value for b: 6 old 8: b:=&b; new 8: b:=6; Enter value for op: '*' old 9: op:=&op;
  • 8. http://placementkit.blogspot.com/ new 9: op:='*'; result=30 PL/SQL procedure successfully completed. P11. Write a program to calculate the commission of the sales man. If salesmade Comm >10000 500 10000 20000 1000 >20000 1500 declare sman varchar(10); sm number(9,2); com number(9,2); begin sman := &sman; sm := &sm; if sm > 10000 then com := 500; elsif sm > 20000 then com := 1000; else com := 1500; end if; dbms_output.put_line(' the sales man name is :' sman); dbms_output.put_line(' the sales made is :' sm); dbms_output.put_line(' the sales commission is :' com); end; Enter value for sman: 'Mathew' old 6: sman:=&sman; new 6: sman:='Mathew'; Enter value for sm: 15000 old 7: sm:=&sm; new 7: sm:=15000; The sales man name is :Mathew The sales made is :15000 The sales commission is :500 PL/SQL procedure successfully completed. PROGRAM BASED ON WHILE LOOP P12. TO GENERATE NUMBERS FROM 0 TO 25 IN STEP OF 5 declare i number :=10 ; begin dbms_output.put_line(' THE WHILE LOOP begins'); WHILE I<=25 LOOP dbms_output.put_line(to_char(i)); i:=i+5; end loop; End; THE WHILE LOOP BEGINS 10 15
  • 9. http://placementkit.blogspot.com/ 20 25 PL/SQL procedure successfully completed. P13. Write a program to find the sum of the digits of the number: DECLARE N number ; S NUMBER :=0; R NUMBER; begin n:=&N; WHILE N<>0 LOOP R := MOD(N,10); S := S + R; N := TRUNC(N/10); end loop; dbms_output.put_line('THE SUM OF THE DIGITS = ' S); end; SQL> Enter value for n: 375 old 7: n:=&N; new 7: n:=375; THE SUM OF THE DIGITS = 15 PL/SQL procedure successfully completed. PROGRAM BASED ON NESTED WHILE LOOP PROGRAM BASED ON FOR LOOP P14. WRITE A PROGRAM CODE TO PRINT THE MULTIPLICATION TABLE OF A GIVEN NO: declare t number(3) := 3; begin T := &T; FOR I IN 1..3 LOOP dbms_output.put_line(t 'X' i '=' i*t ); end loop; end; p15. write aprogram to generate even numbers from 2 to 50, and find its sum. declare i number(5); n number(5); v number(5); s number(5):=0; begin n := &terminal_number; for i in 1 .. n/2 loop v := i*2; s := s+v; dbms_output.put_line(v); end loop; dbms_output.put_line('the sum of numbers from 2 to ' n ' = ' s); end; SQL> /
  • 10. http://placementkit.blogspot.com/ Enter value for terminal_number: 10 old 7: n:=&terminal_number; new 7: n:=10; 2 4 6 8 10 The sum of numbers from 2 to 10 = 30 PL/SQL procedure successfully completed. P16 . WRITE A PROGRAM TO GENERATE FIRST 25 TERMS OF THE FIBONACCIS SERIES. declare a number:= 0 ; b number:= 1; c number; begin dbms_output.put(a ' ' b ' '); for i in 3..10 loop c := a + b; dbms_output.put(c ' '); a := b; b := c; end loop; dbms_output.put_line(' '); end; 0 1 1 2 3 5 8 13 21 34 PL/SQL procedure successfully completed. P17. Write a program to find the factorial of a number : declare n number(2); i number(2); f number(5):=1; begin n :=&n; for i in 1..n loop f := f * i; end loop; dbms_output.put_line(' the factorial value = ' f); end; Enter value for n: 5 old 6: n:=&n; new 6: n:=5; the factorial value = 120 PROGRAM BASED ON NESTED FOR LOOP P18. Write a program to print the following design:
  • 11. http://placementkit.blogspot.com/ 1 12 123 1234 12345 declare i number ; j number; n number; begin n :=&n; for i in 1..n loop for j in 1..i loop dbms_output.put(j); end loop; dbms_output.put_line(' '); end loop; end; Enter value for n: 5 old 6: n:=&n; new 6: n:=5; P19. WRITE A PROGRAM TO DISPLAY NUMBERS OF THE FORM 00000 12345 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 DECLARE I NUMBER; J NUMBER ; K NUMBER; BEGIN FOR I IN 0 .. 5 LOOP FOR J IN 1..5 LOOP K := I*J; DBMS_OUTPUT.PUT(K); END LOOP; DBMS_OUTPUT. PUT_LINE (' '); END LOOP; END; P20. WRITE A PL/SQL CODE TO ACCEPT THE TEXT AND REVERSE THE GIVEN TEXT. CHECK THE TEXT IS PALINDROME OR NOT DECLARE G VARchar2(20); r VARchar2(20); BEGIN G:='&g'; dbms_output.put_line('THE GIVEN TEXT :' G); for i in REVERSE 1.. length(G) loop R:= R substr(G,i,1);
  • 12. http://placementkit.blogspot.com/ end loop; dbms_output.put_line('THE REVERSED TEXT :' R); IF R=G THEN dbms_output.put_line('THE GIVEN TEXT IS PALINDROME '); ELSE dbms_output.put_line('THE GIVEN TEXT IS NOT PALINDROME '); END IF; end; SQL> / Enter value for g: MALAYALAM old 5: G:='&g'; new 5: G:='MALAYALAM'; THE GIVEN TEXT :MALAYALAM THE REVERSED TEXT :MALAYALAM THE GIVEN TEXT IS PALINDROME PL/SQL procedure successfully completed. / Enter value for g: HELLO old 5: G:='&g'; new 5: G:='HELLO'; THE GIVEN TEXT :HELLO THE REVERSED TEXT :OLLEH THE GIVEN TEXT IS NOT PALINDROME PL/SQL procedure successfully completed. P21. Write a program to print the following design: declare i number ; j number; n number; k number; m number; begin n := &n; for i in 1..n loop for j in 1..n-i loop dbms_output.put('~'); end loop; for k in 1..i loop dbms_output.put(k); end loop; for k in reverse 1..i-1 loop dbms_output.put(k); end loop; dbms_output.put_line(' '); end loop; end; Enter value for n: 5 old 8: n:=&n; new 8: n:=5; ~~~~1 ~~~121 ~~12321
  • 13. http://placementkit.blogspot.com/ ~1234321 123454321 PL/SQL procedure successfully completed. P22. Write a program to print the following design : declare i number ; j number; n number; k number; m number; begin n := &n; for i in 1..n loop for j in 1..n-i loop dbms_output.put('~'); end loop; for k in 1..i loop dbms_output.put(k); end loop; for k in reverse 1..i-1 loop dbms_output.put(k); end loop; dbms_output.put_line(' '); end loop; for i in reverse 1..n-1 loop for j in 1..n-i loop dbms_output.put('~'); end loop; for k in 1..i loop dbms_output.put(k); end loop; for k in reverse 1. . i-1 loop dbms_output.put(k); end loop; dbms_output.put_line(' '); end loop; end; Enter value for n: 5 old 8: n:=&n; new 8: n:=5; ~~~~1 ~~~121 ~~12321 ~1234321 123454321 ~1234321 ~~12321 ~~~121 ~~~~1 PL/SQL procedure successfully completed. PROGRAM BASED ON FOR & IF P23. GENERATE ODD NOS: FROM 1 TO 10 AND FIND ITS SUM.
  • 14. http://placementkit.blogspot.com/ DECLARE I NUMBER(4); S NUMBER(4):=0; BEGIN FOR I IN 1..10 LOOP IF MOD(I,2) <> 0 THEN S := S+I; DBMS_OUTPUT.PUT_LINE(I); END IF; END LOOP; DBMS_OUTPUT.PUT_LINE(' THE SUM OF ODD NOS FROM 1 TO 10 = ' S); END; SQL>/ 1 3 5 7 9 THE SUM OF ODD NOS FROM 1 TO 10 = 25 PL/SQL procedure successfully completed. P24 . WRITE A PROGRAM TO ALL ODD NUMBERS FORM 10 TO 1 IN REVERSE ORDER. declare i number(5); n number(5); v number(5); s number(5) :=0; begin S := &STARTING_NUMBER; n := &terminal_number; for i in REVERSE S .. N loop IF MOD (I,2) <>0 THEN s := s + I; dbms_output.put_line(I); end loop; dbms_output.put_line('the sum of numbers from 2 to ' n ' = ' s); end; Enter value for starting number : 1 Old 6: s=&starting_number:1 New 6: s:=1; Enter value for Terminal_number: 10 old 7: n := &terminal_number; new 7: n:=10; 9 7 5 3 1 The sum of numbers from 1 to 9 = 25 PL / SQL procedure successfully completed. P25. Write a program to check the given no: is prime or not:
  • 15. http://placementkit.blogspot.com/ declare n number; i number; pr number(2):=1; begin n:= &n; for i in 2..n/2 loop if mod(n,i) = 0 then pr := 0; end if; end loop; if pr = 1 then dbms_output.put_line(' the given no: is prime: ' n); else dbms_output.put_line(' the given no: is not prime: ' n); end if; end; Enter value for n: 7 old 6: n:=&n; new 6: n:=7; the given no: is prime: 7 PL/SQL procedure successfully completed. SQL> / Enter value for n: 25 old 6: n:=&n; new 6: n:=25; the given no: is not prime: 25 PL/SQL procedure successfully completed. P26. WRITE A PROGRAM TO PRINT ASCII TABLE : DECLARE I NUMBER; BEGIN FOR I IN 33..256 LOOP DBMS_OUTPUT.PUT (( TO_CHAR (I,'000')) ':' CHR(I) ' ' ); IF MOD (I, 8) = 0 THEN DBMS_OUTPUT.PUT_LINE(' '); END IF; END LOOP; END; 033:! 034:" 035:# 036:$ 037:% 038:& 039:' 040:( 041:) 042:* 043:+ 044:, 045:- 046:. 047:/ 048:0 049:1 050:2 051:3 052:4 053:5 054:6 055:7 056:8 249:ù 250:ú 251:û 252:ü 253:ý 254:þ 255:ÿ 256: :: :: :: :: :: :: :: :: :: :: :: :: PL/SQL procedure successfully completed. P27. Write a program to generate prime nos from 1 to 10:
  • 16. http://placementkit.blogspot.com/ declare n number; i number; pr number; begin for n in 1..10 loop pr:=1; for i in 2 .. n/2 loop if mod(n,i) = 0 then pr := 0; end if; end loop; if pr = 1 then dbms_output.put_line(n); end if; end loop; end; 1 2 3 5 7 P28 . Write a program to check the square root of a number is prime or not. declare n number; i number; pr number; begin pr := 1; n := &n; n := sqrt(n); for i in 2 .. n/2 loop if mod(n,i) = 0 then pr := 0; end if; end loop; if pr = 1 then dbms_output.put_line('the square root of the given number is prime' n*n); else dbms_output.put_line('the square root of the given number is not prime' n*n ); end if; end; SQL> Enter value for n: 81 old 7: n:=&n; new 7: n:=81; The square root of the given number is not prime81 PL/SQL procedure successfully completed. PROGRAM BASED ON LOOP... END LOOP P29. Write a program to reverse the digits of the number:
  • 17. http://placementkit.blogspot.com/ DECLARE N number ; S NUMBER : = 0; R NUMBER; K number; begin N := &N; K := N; LOOP EXIT WHEN N = 0 ; S := S * 10; R := MOD(N,10); S := S + R; N := TRUNC(N/10); end loop; dbms_output.put_line( ' THE REVERSED DIGITS ' ' OF ' K '=' S); end; Enter value for n: 4567 old 7: N:=&N; new 7: N:=4567; THE REVERSED DIGITS OF 4567 = 7654 PL/SQL procedure successfully completed. PROGRAM BASED ON RECORDS P30. WRITE PL/SQL SCRIPT TO CREATE A RECORD TYPE THAT CAN HOLD SALES IN 4 DIFFERENT QUARTERS. Structure of the table : SALES ( SNO, NAME, QUAD1, QUAD2, QUAD3, QUAD4 ) SALES2004 ( Q1, Q2, Q3, Q4 ) DECLARE TYPE SALEREC IS RECORD ( Q1 NUMBER, Q2 NUMBER, Q3 NUMBER, Q4 NUMBER, ); BEGIN SREC SALEREC ; SELECT SUM(QUAD1) , SUM(QUAD2) , SUM(QUAD3), SUM(QUAD4) INTO SREC FROM SALES ; INSERT INTO SALES2004 VALUES (SREC.Q1 ,SREC.Q2, SREC.Q3, SREC.Q4); END; PROGRAM BASED ON DATABASE INTERACTION P31 . Write PL/SQL SCRIPT to determine the salary of employee in the EMP tab le. If salary >7500 give an increment of 15% , otherwise display the message NO INCREMENT . Get the empno from the user. DECLARE ENO EMP.EMPNO%TYPE; SALARY EMP.SAL%TYPE; BEGIN ENO := &ENO;
  • 18. http://placementkit.blogspot.com/ SELECT SAL INTO SALARY FROM EMP WHERE EMPNO=ENO; IF SALARY >7500 THEN UPDATE EMP SET SAL =SAL+SAL* 15/100 WHERE EMPNO=ENO; ELSE DBMS_OUTPUT.PUT_LINE(NO INCREMENT) END IF; END; P32 . GIVEN A TABLE STUDENT ( SID INTEGER PRIMARY KEY, NAME CHAR(30), AGE INTEGER , GPA FLOAT ). WRITE A PL/SQL SCRIPT TO GO THROUGH SID 142- 857 AND SET ALL GPA UNDER 4.0 TO 4.0 . DECLARE TSID STUDENT.SID%TYPE; TGPA STUDENT.GPA%TYPE; BEGIN TSID:=142; LOOP EXIT WHEN TSID > 857 ; SELECT GPA INTO TGPA FROM STUDENT WHERE SID=TSID; IF TGPA< 4.0 THEN UPDATE STUDENT SET GPA=4.0 WHERE SID=TSID; END IF; TSID:=TSID+1; END LOOP; END; P33 . DISPLAY AVERAGE SALARY , TOTOL NO: OF EMP, AND TOTAL SALARY FOR FIRST 5 DEPARTMENTS IN EMP TABLE. DEPT NO ARE 10,20,30,40,5090. DECLARE DNO NUMBER:=10; DPNAME DEPT. DNAME%TYPE; ASAL EMP. SAL%TYPE; ACOUNT NUMBER; SSAL EMP. SAL%TYPE; BEGIN LOOP EXIT WHEN DNO > 50; SELECT DNAME INTO DPNAME FROM DEPT WHERE DEPTNO=DNO; SELECT AVG(SAL), COUNT(*), SUM(SAL) INTO ASAL, ACOUNT,SSAL FROM EMP WHERE DEPTNO = DNO; DBMS_OUTPUT.PUT_LINE( DEPARTMENT NAME DPNAME); DBMS_OUTPUT.PUT_LINE( DEPARTMENT COUNT ACOUNT); DBMS_OUTPUT.PUT_LINE( AVERAGE SALARY ASAL); DBMS_OUTPUT.PUT_LINE( SUM SALARY SSAL); DNO := DNO+10; END LOOP; END;
  • 19. http://placementkit.blogspot.com/ P34. WRITE A PL/SQL SCRIPT TO COUNT THE NO: OF EMPLOYEES. IF TOTAL <10 DISPLAY SMALL COMPANY, ELSE IF TOTAL BETWEEN 10-50 DISPLAY MEDIUM ELSE DISPLAY LARGE . DECLARE TOT NUMBER (3); BEGIN SELECT COUNT(*) INTO TOT FROM EMP; IF TOT <10 THEN TEXT := SMALL ; ELSIF TOT<50 THEN TEXT := MEDIUM; ELSE TEXT := LARGE; END IF; DBMS_OUTPUT.PUT_LINE( TEXT COMPANY); END; P35. Find the employee drawing minimum salary. Add his details like empno, n ame, sal into the table newsal, after incrementing Rs.700. DECLARE ENO EMP.EMPNO%TYPE; NAME EMP.ENAME%TYPE; SALARY EMP.SAL%TYPE; BEGIN SELECT EMPNO, ENAME, SAL INTO ENO, NAME, SALARY FROM EMP WHERE SAL = (SELECT MIN(SAL) FROM EMP); SALARY := SALARY+700; INSERT INTO NEWSAL VALUES ( ENO,NAME,SALARY); END; P36. Write a program to update the salary of the employee by 25% if he earns salary >4000, otherwise if salary <4000 update by 10%, else update by 15%. DECLARE S NUMBER(8,2) ; NAME VARCHAR2(10); BEGIN NAME:=&NAME; SELECT SAL INTO S FROM EMP WHERE ENAME = NAME; IF S >4000 THEN UPDATE EMP SET SAL := SAL+SAL*20/100 WHERE ENAME=NAME; ELSIF S<4000 UPDATE EMP SET SAL := SAL+SAL*10/100 WHERE ENAME=NAME; ELSE UPDATE EMP SET SAL := SAL+SAL*15/100 WHERE ENAME=NAME; END IF; END; P37 .Write PL/SQL code to increase the sal of an employee by 5% whose salary is more than 4000 . Get the empno from the user. DECLARE ENO NUMBER(4); BEGIN
  • 20. http://placementkit.blogspot.com/ ENO := &ENO; UPDATE EMP SET SAL =SAL+SAL*5/100 WHERE SAL>4000 AND EMPNO=ENO; END; P38. GIVEN A TABLE TEMP ( SNO NUMBER(3) , DNO NUMBER,TEXT CHAR (4) . WRITE A PL/SQL SCRIPT TO INSERT 10 RECORDS IN TABLE TEMP AS PER THE FOLLOWING SPECIFICA TIONS: SNO DNO TEXT 1 50 ODD 2 100 EVEN 3 150 ODD DECLARE SNO NUMBER := 1; DNO NUMBER ; TEXT CHAR(5) ; BEGIN LOOP EXIT WHEN SNO > 10; DNO := SNO * 50; IF MOD ( SNO, 2 ) = 0 TEXT := EVEN; ELSE TEXT := ODD; INSERT INTO TEMP VALUES (SNO,DNO,TEXT); SNO := SNO + 1; END LOOP; COMMIT; END; P39 . Write PL/SQL code to DELETE the record of an employee whose salary is more than 4000 . Get the empno from the user. DECLARE ENO NUMBER(4); BEGIN ENO := &ENO; DELETE FROM EMP WHERE SAL>4000 AND EMPNO=ENO; END; P40 .Write PL/SQL code to insert a new record in the table emp after obtaining values ( empno, ename, hiredate, sal ) from user. declare tempno number(4); tename varchar(10); thiredate varchar2(12); tsal number(7,2); begin tempno :=&tempno; tename :='&tename'; thiredate :='&thiredate'; tsal := &tsal; insert into emp (empno,ename,hiredate,sal) values(tempno,tename,to_date(thir
  • 21. http://placementkit.blogspot.com/ edate,'DD-mon-yyyy'),tsal); end; Enter value for tempno: 8000 old 7: tempno:=&tempno; new 7: tempno:=8000; Enter value for tename: mathew old 8: tename :='&tename'; new 8: tename :='mathew'; Enter value for thiredate: 10-jan-2004 old 9: thiredate :='&thiredate'; new 9: thiredate :='10-jan-2004'; Enter value for tsal: 8000 old 10: tsal := &tsal; new 10: tsal := 8000; PL/SQL procedure successfully completed. P41. WRITE A PROGRAM TO CREATE A EMP %ROWTYPE RECORD .ACCEPT THE EMPNO FROM THE USER, AND DISPLAY ALL THE INFORMATION ABOUT THE EMPLOYEE. declare erec emp%rowtype; eno emp.empno%type; begin eno := &eno; select * into erec from emp where empno=eno; dbms_output.put_line( 'Emp no : ' erec.empno) ; dbms_output.put_line( 'Name : ' erec.ename) ; dbms_output.put_line( 'Salary : ' erec.sal); dbms_output.put_line( 'Deptno : ' erec.deptno); dbms_output.put_line( 'hiredate: ' erec.hiredate); dbms_output.put_line( 'job : ' erec.job); end; SQL> / Enter value for eno: 7788 old 5: eno := &eno; new 5: eno := 7788; Emp no : 7788 Name : SCOTT Salary : 1452 Deptno : 20 hiredate: 19-APR-87 job : ANALYST PL/SQL procedure successfully completed. PROGRAM BASED ON EXCEPTION P42. Write PL/SQL script that traps an invalid data type value given and displays a custom error message. DECLARE ENO EMP. EMPNO%TYPE; SNO VARCHAR2(5); NAME EMP.ENMAE%TYPE; BEGIN SNO := &SNO ;
  • 22. http://placementkit.blogspot.com/ SELECT EMPNO,ENAME INTO ENO,NAME FROM EMP WHERE EMPNO=SNO; DBMS_OUTPUT.PUT_LINE ( NAME ENAME EMPNO EMPNO); EXCEPTION WHEN INVALID_NUMBER THEN DBMS_OUTPUT.PUT_LINE(SNO IS INVALID DATA FOR EMPLOYEE ID); END; PROGRAM BASED ON FUNCTIONS P43 . write a function to create factorial of a number. CREATE OR REPLACE FUNCTION FACT (N NUMBER) RETURN NUMBER IS I NUMBER(10); F NUMBER :=1; BEGIN FOR I IN 1.. N LOOP F:= F*I; END LOOP; RETURN F; END; SQL> / Function created. SQL> select fact(8) from dual; FACT(8) --------- 40320 PROGRAM BASED ON PROCEDURES P44. Write a Procedure to increase the salary for all the employees in the EMP table : SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO --------- ---------- --------- --------- --------- --------- --------- ----- ---- 7369 SMITH CLERK 7902 17-DEC-80 800 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 14 rows selected. SQL> create or replace procedure inc(i number) is begin update emp set sal =sal+i; end; / Procedure created. To execute the procedures in the PL/SQL block: SQL> declare begin inc(100); end; / PL/SQL procedure successfully completed. SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
  • 23. http://placementkit.blogspot.com/ 7369 SMITH CLERK 7902 17-DEC-80 800 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1700 300 30 14 rows selected. P45. WRITE A PROCEDURE TO INCREASE THE SALARY FOR THE SPECIFIED EMPLOLEE USING EMPNO IN THE EMP TABLE BASED ON THE FOLLOWING CRITERIA: INCREASE THE SALARY BY 5% FOR CLERKS, 7% FOR SALESMAN , 10% FOR ANALYST, 20 % FOR MANAGER and 25% FOR PRESIDENT. ACTIVATE USING PL/SQL BLOCK. SQL> SELECT * FROM EMP; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPT 7369 SMITH CLERK 7902 17-DEC-80 800 20 CREATE OR REPLACE PROCEDURE DESIGNATION(ENO NUMBER) IS BEGIN UPDATE EMP SET SAL=SAL+SAL*5/100 WHERE JOB ='CLERK' AND EMPNO=ENO; UPDATE EMP SET SAL=SAL+SAL*7/100 WHERE JOB='SALESMAN' AND EMPNO=ENO; UPDATE EMP SET SAL=SAL+SAL*10/100 WHERE JOB='ANALYST' AND EMPNO=ENO; UPDATE EMP SET SAL=SAL+SAL*20/100 WHERE JOB='MANAGER' AND EMPNO=ENO; UPDATE EMP SET SAL=SAL+SAL*25/100 WHERE JOB='PRESIDENT' AND EMPNO=ENO; END; SQL> / Procedure created. SQL> DECLARE 2 BEGIN 3 DESIGNATION(7369); 4 END; 5/ PL/SQL procedure successfully completed. SQL> SELECT * FROM EMP; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPT 7369 SMITH CLERK 7902 17-DEC-80 840 20__