PL/SQL Programming Exercises for Beginners, Schemes and Mind Maps of Computer science

A series of pl/sql programming exercises and solutions, covering fundamental concepts such as variable declaration, conditional statements, loops, procedures, functions, and cursors. It includes examples of basic arithmetic operations, finding minimum values, checking for odd or even numbers, and displaying numbers using loops. Additionally, it demonstrates how to create tables and insert values using pl/sql, as well as how to use cursors to iterate through data. These exercises are designed to help students understand and apply pl/sql programming techniques in database management. Suitable for high school students learning programming basics.

Typology: Schemes and Mind Maps

2021/2022

Available from 06/22/2025

susmit-debnath
susmit-debnath 🇮🇳

5 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PL/SQL
1.Write a PL/SQL program to find the sum of 2 numbers.
SQL> set serveroutput on;
SQL> declare
2 a number(2);
3 b number(2);
4 c number(2);
5 begin
6 a:=21;
7 b:=28;
8 c:=a+b;
9 dbms_output.put_line('sum='||c);
10 end;
11 /
sum=49
PL/SQL procedure successfully completed.
2. Write a PL/SQL program to check maximum of 2 numbers.
SQL> declare
2 a number(2);
3 b number(2);
4 begin
5 a:=21;
6 b:=28;
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download PL/SQL Programming Exercises for Beginners and more Schemes and Mind Maps Computer science in PDF only on Docsity!

PL/SQL

1.Write a PL/SQL program to find the sum of 2 numbers. SQL> set serveroutput on; SQL> declare 2 a number(2); 3 b number(2); 4 c number(2); 5 begin 6 a:=21; 7 b:=28; 8 c:=a+b; 9 dbms_output.put_line('sum='||c); 10 end; 11 / sum= PL/SQL procedure successfully completed.

  1. Write a PL/SQL program to check maximum of 2 numbers. SQL> declare 2 a number(2); 3 b number(2); 4 begin 5 a:=21; 6 b:=28;

7 if (a>b) then 8 dbms_output.put_line('a is largest'); 9 else 10 dbms_output.put_line('b is largest'); 11 end if; 12 end; 13 / b is largest PL/SQL procedure successfully completed.

  1. Write a PL/SQL program to check the given number is odd or even number. SQL> declare 2 a number(2):=21; 3 b number(2):=2; 4 begin 5 if mod(a,b)=0 then 6 dbms_output.put_line('a is even number'); 7 else 8 dbms_output.put_line('a is odd number'); 9 end if; 10 end; 11 / a is odd number PL/SQL procedure successfully completed.
  1. Display the numbers from 1 to 10 using for loop. SQL> declare 2 i number(2); 3 begin 4 for i in 1..10 loop 5 dbms_output.put_line(i); 6 end loop; 7 end; 8 / 1 2 3 4 5 6 7 8 9 10 PL/SQL procedure successfully completed.
  2. Find minimum of the two numbers using procedure. SQL> declare 2 a number(2); 3 b number(2);

4 c number(2); 5 procedure findmin(x in number,y in number,z out number) is 6 begin 7 if(x<y) then 8 z:=x; 9 else 10 z:=y; 11 end if; 12 end; 13 begin 14 a:=21; 15 b:=28; 16 findmin(a,b,c); 17 dbms_output.put_line('min of two values'||c); 18 end; 19 / min of two values PL/SQL procedure successfully completed.

  1. Find the sum of two numbers without initializing the numbers. SQL> declare 2 a number(2); 3 b number(2); 4 c number(2); 5 begin

9 c:=a+b; 10 dbms_output.put_line('sum'||c); 11 end; 12 / sum PL/SQL procedure successfully completed.

  1. Creation of areas tables and insertion of values using PL/SQL. SQL> create table areas(radius number(3),area number(6)); Table created. SQL> declare 2 radius areas.radius%type; 3 area areas.area%type; 4 pi number:=3.14; 5 begin 6 radius:=4; 7 while(radius<=8) loop 8 area:=piradiusradius; 9 insert into areas values(radius,area); 10 radius:=radius+1; 11 end loop; 12 end; 13 / PL/SQL procedure successfully completed.

SQL> select * from areas; RADIUS AREA


4 50 5 79 6 113 7 154 8 201

  1. Write a PL/SQL program using cursors. SQL> declare 2 cursor c1 is select * from areas; 3 r areas.radius%type; 4 a areas.area%type; 5 begin 6 open c1; 7 loop 8 fetch c1 into r,a; 9 exit when c1%notfound; 10 if(a>100) then 11 dbms_output.put_line('radius is above 6'); 12 else 13 dbms_output.put_line('radius is below 6'); 14 end if; 15 end loop;

13 return z; 14 end; 15 begin 16 a:=21; 17 b:=28; 18 c:=findmin(a,b); 19 dbms_output.put_line('min of two values'||c); 20 end; 21 / min of two values PL/SQL procedure successfully completed.