Assignment No 5
Assignment No 5
Assignment No: 5
Class: T.E. Computer Roll No:
Aim: Write a PL/SQL block to calculate the area of a circle for a value of radius
varying from 5 to 9.
Problem Statement:
Write a PL/SQL code block to calculate the area of a circle for a value of radius varying from 5 to 9.
Store the radius and the corresponding values of calculated area in an empty table named areas,
consisting of two columns, radius and area.
Objective:
Architecture of PL/SQL:
1. PL/SQL block
2. PL/SQL Engine
3. Database Server
PL/SQL block:
PL/SQL Engine
PL/SQL engine is the component where the actual processing of the codes takes place.
PL/SQL engine separates PL/SQL units and SQL part in the input (as shown in the image below).
The separated PL/SQL units will be handled with the PL/SQL engine itself.
The SQL part will be sent to database server where the actual interaction with database
takes place.
It can be installed in both database server and in the application server.
Database Server:
This is the most important component of Pl/SQL unit which stores the data.
The PL/SQL engine uses the SQL from PL/SQL units to interact with the database server.
It consists of SQL executor which actually parses the input SQL statements and execute the same.
Declarations
1 This section starts with the keyword DECLARE. It is an optional section and defines all variables,
cursors, subprograms, and other elements to be used in the program.
Executable Commands
2 This section is enclosed between the keywords BEGIN and END and it is a mandatory section. It
consists of the executable PL/SQL statements of the program. It should have at least one executable line
of code, which may be just a NULL command to indicate that nothing should be executed.
Exception Handling
3 This section starts with the keyword EXCEPTION. This optional section contains exception(s) that
handle errors in the program.
Every PL/SQL statement ends with a semicolon (;). PL/SQL blocks can be nested within other PL/SQL
blocks using BEGIN and END. Following is the basic structure of a PL/SQL block −
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
<exception handling>
END;
DECLARE
BEGIN
dbms_output.put_line(message);
END;
PL/SQL Placeholders
Placeholders are temporary storage area. PL/SQL Placeholders can be any of Variables, Constants and
Records. Oracle defines placeholders to store data temporarily, which are used to manipulate data during
the execution of a PL SQL block.
Depending on the kind of data you want to store, you can define placeholders with a
name and a datatype. Few of the datatypes used to define placeholders are as given below.
Number (n,m) , Char (n) , Varchar2 (n) , Date , Long , Long raw, Raw, Blob, Clob, Nclob, Bfile
PL/SQL Variables
These are placeholders that store the values that can change through the PL/SQL Block.
For example, if you want to store the current salary of an employee, you can use a variable.
DECLARE
salary number (6);
The below example declares two variables, one of which is a not null.
DECLARE
salary number(4);
The below example declares two variables, one of which is a not null.
DECLARE
salary number(4);
The below example declares two variables, one of which is a not null.
DECLARE
salary number(4);
Conclusion:
Thus we have successfully implemented PL/SQL block to calculate the area of a circle for a
value of radius varying from 5 to 9.