Вы находитесь на странице: 1из 3

PRACTICAL 1

AIM : INTRODUCTION TO PL/SQL

PL/SQL : In Oracle database management, PL/SQL is a procedural language extension to


Structured Query Language (SQL). The purpose of PL/SQL is to combine database language and
procedural programming language. The basic unit in PL/SQL is called a block and is made up of
three parts: a declarative part, an executable part and an exception-building part.

PL/SQL blocks are defined by the keywords DECLARE, BEGIN, EXCEPTION and END,
which divide the block into a declarative part, an executable part and an exception-building part,
respectively. The declaration section of the block is used to define and initialize constants and
variables; if a variable is not initialized, it will default to NULL value. Blocks can be nested and
submitted to interactive tools, like SQL*Plus.

Key Differences Between SQL and PL/SQL

1. The basic difference between two languages is that SQL executes the single query at a time
whereas, Pl/SQL executes the block of code at once.
2. SQL is a Structured Query Language whereas, PL/SQL is a Procedural Language/ Structured
Query Language.
3. SQL act as a source to retrieve data that will be displayed by the application created using
PL/SQL.
4. SQL queries and commands are written using DDL (Data Definition Language), DML (Data
Manipulation Language). However, using PL/SQL you can write programming block which
has procedures, functions, triggers, packages, variables within its syntax.
5. SQL queries are used to retrieve data from the database; you can also add or delete or modify
the data in the database. On the other hands, PL/SQL is used to create applications that can
display the information retrieved by the SQL.
6. You can embed SQL queries within the syntax of PL/SQL. However, the opposite is not
possible.

Block Structure

PL/SQL program units organize the code into blocks.

1) Anonymous block : It is a block without a name. The anonymous block is the simplest unit in
PL/SQL. It is called anonymous block because it is not saved in the Oracle database. An
anonymous block is an only one-time use and useful in certain situations such as creating test
units.

2) Named block : That’s PL/SQL blocks which having header or labels are known as Named
blocks. These blocks can either be subprograms like functions, procedures, packages or Triggers.
Example:

BEGIN

dbms_output.put_line (‘Hello World..');

END;

Output :

Hello World..

PL/SQL Character sets

1. Letters : A–Z, a–z


2. Digits : 0–9
3. Symbols : ~ ! @ # $ % * () _ – + = | : ; " ' < > , . ? / ^
4. Whitespace : Tab, space, newline, carriage return

PL/SQL Literals

1. Character : A character literal is an individual character enclosed by single quotes (').


2. String : String literal is a sequence of zero or more characters enclosed by single quotes.
3. BOOLEAN : BOOLEAN literals are the predefined values TRUE, FALSE, and NULL.
NULL stands for a unknown value.
4. Number: It can be integer or float.

PL/SQL Data Types

1. Numeric : Numeric values on which arithmetic operations are performed.


2. Character : Alphanumeric values that represent single characters or strings of characters.
3. Boolean : Logical values on which logical operations are performed.
4. Datetime : Dates and times.
5. ROWID : Physical row identifier, the address of a row in an ordinary table.
6. Constant : Fixed value.
7. RAW : It is used to store binary data or byte strings.
8. BLOB
9. CLOB
10. BFILE
11. LOB etc
12. Comments : It can be single line or multiple line.

Вам также может понравиться