0% found this document useful (0 votes)
16 views

rdbms2 (1)

The document contains a series of PL/SQL code snippets for various programming tasks, including inserting data into a table, calculating salary components, checking number properties (like positive/negative, even/odd, palindrome, Armstrong), generating Fibonacci series, and performing string manipulations. Each task is presented with a brief description followed by the corresponding PL/SQL code. The document serves as a practical guide for implementing common database operations and calculations using PL/SQL.

Uploaded by

ry6492yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

rdbms2 (1)

The document contains a series of PL/SQL code snippets for various programming tasks, including inserting data into a table, calculating salary components, checking number properties (like positive/negative, even/odd, palindrome, Armstrong), generating Fibonacci series, and performing string manipulations. Each task is presented with a brief description followed by the corresponding PL/SQL code. The document serves as a practical guide for implementing common database operations and calculations using PL/SQL.

Uploaded by

ry6492yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

2202040601109 RAJAN YADAV

Problem Sheet 2
1) To write PL/SQL block for inserting rows into EMPDET table with the following calculation:

HRA=50% OF BASIC

DA=20% OF BASIC

PF=7% OF BASIC

NETPAY=BASIC+DA+HRA-PF

 BEGIN

INSERT INTO EMPDET (BASIC,HRA,DA,PF,NETPAY)

VALUES(1000,(1000*50/100),(1000*20/100),(1000*7/100,)(1000+(1000*20/100)+(1000*50/10
0)));

END;

2) Write PL/SQL code fpr finding minimum and maximum number.

 DECLARE

min_number NUMBER;

max_number NUMBER;

BEGIN

SELECT

MIN(number), MAX(number) INTO

Min_number,max_number FROM table_name;

DBMS_OUTPUT.PUT_LINE(‘Min number is : ‘ || min_number);

DBMS_OUTPUT.PUT_LINE(‘Max number is ’ || max_number);

END;

3) Write PL/SQL code for check given number is zero,positive or negative.

 DECLARE

n NUMBER;

1|P age
2202040601109 RAJAN YADAV
n:=:n;

IF n > 0 THEN

DBMS_OUTPUT.PUT_LINE(‘The number is positive’);

ELSEIF n = 0 THEN

DBMS_OUTPUT.PUT_LINE(‘The number is zero’);

ELSE

DBMS_OUTPUT.PUT_LINE(‘The number is negative’);

ENDIF;

END;

4) Write PL/SQL code for check given number is even or odd.

 DECLARE

n NUMBER :=:n;

is_odd BOOLEAN;

BEGIN

Is_odd:=n/2=1;

IF is_odd THEN

DBMS_OUTPUT.PUT_LINE(n || ‘is odd’);

ELSE

DBMS_OUTPUT.PUT_LINE(n || ‘is even’);

ENDIF;

END;

5) Write PL/SQL code for display Fibonacci series.

2|P age
2202040601109 RAJAN YADAV

 DECLRE

I INTEGER := 0;J

INTEGER :=1; N

INTEGER :=n;

BEGIN

FOR counter IN 1..n LOOP

DBMS_OUTPUT.PUT_LINE(i+j);

I:=j;

J:= i+j;

END LOOP;

END;

6) Write PL/SQL code for calculate factorial for given number.

 DECLARE

n NUMBER;

fact NUMBER;

BEGIN

n:=: n;

fact :=factc*n;

3|P age
2202040601109 RAJAN YADAV

n:= n-1;

END LOOP;

Dbms_output.put_line(fact);

END;

7) Write PL/SQL code for swapping of two numbers.

 DECLARE

X number :=: x;

Y number :=: y;

Temp number;

BEGIN

Dbms_output.put_line(‘before swapping’);

Dbms_output.put_line(‘X=’||x);

Dbms_output.put_line(‘Y=’||y);

END;

8) Write PL/SQL code for find length for given string.

4|P age
2202040601109 RAJAN YADAV

 DECLARE

Str VARCHAR 2(100):=:str;

Str_len INTEGER;

BEGIN

Str_len := LENGTH(str);

DBMS_OUTPUT.PUT_LINE(‘The length of the given string is : ’||str_len);

END:

9) Write PL/SQL coide for find given number is palindrome or not.

 DECLARE

n NUMBER;

rev NUMBER;

temp NUMBER;

BEGIN

n:=:num;

temp:=n;

rev:=0;

WHILE (n>0)LOOP

Rev:=rev*10+(n MOD 10);

N:=n/10;

END LOOP

IF(temp =rev) THEN

DBMS_OUTPUT.PUT_LINE(‘given number is palindrome’);

ELSE
Mrunali Goyani

5|P age
2202040601109 RAJAN YADAV

DBMS_OUTPUT.PUT_LINE(‘given number is not palindrome’);

ELSEIF

END;

10) Writing PL/SQL block for checking Armstrong number.

 DECLARE

n number:=:num;

s number:=0;

r number;

len number;

m:=n;

len:=length(to_char(n));

while n>0

loop

r:= mod(n,10);

s:= s+power(r,len);

n:= trunc(n/10);

end loop;

if m=s

then

dbms_output.put_line(‘given number is a armsrong number’);

else

dbms_output.put_line(‘given number is not a Armstrong number’);

6|P age
2202040601109 RAJAN YADAV

end if;

end;

11) Write PL/SQL code for count frequency of character in inputted string.

 DECLARE

Strlnput VARCHAR(50);

Strchar VARCHAR(1);

Intfreq INT;

BEGIN

Strlnput:=: strlnput;

Strchar:=: strchar;

Intfreq:=:0;

FOR I IN 1..LENGTH(strlnput)

LOOP

IF SUBSTR(strlnput,I,1)=strChar THEN

Intfreq:= intfreq+1;

END IF:

END LOOP;

dbms_output.put_line(strchar ||’appears’ || intfreq ||’times in the given string’);

END;

7|P age
2202040601109 RAJAN YADAV

12) Write PL/SQL code for convert string into uppercase and lopwercase.

 DECLARE

Str VARCHAR(50):=:str;

Str_upper VARCHAR(50);

Str_lowre VARCHAR(20);

BEGIN

Str_upper:=UPPER(str);

Str_LOWER:=LOWER(str);

DBMS_OUTPUT.PUT_LINE(‘upper case :’||str_upper);

DBMS_OUTPUT.PUT_LINE(‘lower case :’||str_lower);

END;

13) Write PL/SQL code to generate reverse number of given number.

 DECLARE

num number (10):=:num;

re_num number(10):=0;

rem number(10);

BEGIN

WHILE (num>0) LOOP

rem := mod(num,10);

rev_num:= (rev_num*10)+rem;

num:=trunc(num/10);

END LOOP

8|P age
2202040601109 RAJAN YADAV

DBMS_OUTPUT.PUT_LINE(‘Reverse number of given number is : ‘||rev_num);

END:

14) Write PL/SQL code for accept two integer from user and perform arithmetic.

 DECLARE

num1 number:=:num1;

num2 number:=:num2;

BEGIN

Dbms_output.put_line(‘sum of two numbers: ’||(num1+num2));

Dbms_output.put_line(‘difference of two numbers: ’||(num1-num2));

Dbms_output.put_line(‘Multiplication of two numbers: ’||(num1*num2));

Dbms_output.put_line(‘divison of two numbers: ’||(num1/num2));

END;

15) Write PL/SQL block that will accept employee number from user and deduct an amount of
Rs.200 from the inputted employee,if he has a salary less than 1000 after salary is deducted,
It display message ‘salary is less than 1000’ the process is to be fired on the employee table
employee(emp_no,name,salary).

 Create table employee(

Emp_no numeric(10)primary key,

Name varchar(250),

Salary numeric(7)

9|P age
2202040601109 RAJAN YADAV

Insert all

Insert into employee values(1,’MK’,1500)

Insert into employee values(2,’MG’,5000)

Insert into employee values(3,’AK’,3000)

Insert into employee values(4,’NTR’,4000)

Insert into employee values(5,’RAJU’,2000)

DECLARE

Emp_no number;

Salary NUMBER;

BEGIN

SELECT salary INTO emp_no FROM employee WHERE

Emp_no=:emp_no;

IF salary <1000 THEN

UPDATE employee SET salary =salary-200 WHERE emp_n=:emp_no;

DBMS_OUTPUT.PUT_LINE(‘Salary is less than 1000’);

END IF;

END;

16) Write PL/SQL block to calculate the area of circle for a value of radius varying from 4 To 8.
Store the radius and corresponding value of calculated area in table areas.Areas (Radius,
area).

Create table areas

Radius number (8, 2),

Area number (8, 2)

);

 DECLARE

area NUMBER;

BEGIN

FOR I IN 4..8 LOOP

10 | P a g e
2202040601109 RAJAN YADAV

area :=3.14159*i*I;

INSERT INTO Areas(Radius,Area) VALUES (I,area);

END LOOP;

END;

11 | P a g e

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