SlideShare a Scribd company logo
PL/SQL:
A PROGRAMMING LANGUAGE & CONTROL
STRUCTURES
PL/SQL:
A PROGRAMMING LANGUAGE. The standard
query language for relationship database is SQL
(Structured query language ).structured query language is a
fourth –generation , high level, nonprocedural language.
The PL/SQL also possess features of object-oriented
languages, such as:
Data encapsulation.
Error handling.
Information hiding.
Object-oriented programming(OOP).
HISTORY OF PL/SQL
 Built-in package.
 Error handling.
 The transaction control statements
SAVEPOINT,ROLLBACK,AND COMMIT.
 The DML statements INSERT,DELETE, AND UPDATE.
 Built-in functions –character, numeric, conversion, and
date functions.
 Modular programming with procedures and functions.
 Programmer- defined subtypes.
 Stored procedures, functions, and packages.
 DDL support through the DBMS –SQL package.
 Database access through work areas called cursors.
FUNDAMENTALS
A PL/SQL program constants of statements . You may
use upper or lowercase letters in your program.
RESERVED WORDS
IDENTIFIERS
LITERALS
COMMENTS
RESERVED WORDS
The reserved words or by words are words provided but
the language that have a specific use in the language.
Example –end , if while, package.
IDENTIFIERS
User –defined identifiers used to name variables,
constants, procedures, functions cursors, tables, records and
exception.
RULES
The name can be from 1to 30 characters in length.
The name must start with a letter .
Spaces are not allowed.
Other special character are not allowed.
LITERALS
Literals are values that are not represented by user-defined
identifiers.
THREE TYPES of literals:
Numeric
Character
Boolean
PL/SQL BLOCK STRUTURE
PL/SQL is a block structured language. A program can be
dividend into logical blocks.
TWO TYPES
Anonymous block
Named block
1.ANONYMOUS BLOCK
An anonymous block is a block of code without a name.
2.NAMED BLOCK
A subprogram is a named block that can be called and
can take arguments.
COMMENTS
Comments are used to document program. They are
written as part of a program but they are executed . In fact
comments are ignored by the PL/SQL engine.
1.To write a single line comments two dashes(--)are
entered at the beginning of a new line.
EXAMPLE:
--This is a single line comment
2.To write a multiline comment text is placed between
/*and*/. A multiline comment can be written on a separate
line .
EXAMPLE:
/*This is a multiline comment that ends here */
Scalar
Composite
Reference
LOB
DATA TYPES:
SCALAR
DATA
TYPE
CHARACTER
NUMBER
BOOLEAN
DATE
1.Character:
Variables with a character data type can store text. The
text may include letters , number & special characters.
Character data type include ;
CHAR.
VARCHAR.
2.NUMBER:
Whole numbers or integer values can be handled by
following data types.
BINARY INTEGER.
INTEGER.
INT.
SMALLINT.
POSITIVE.
NATURAL.
2.BOOLEaN :
It is used for Boolean data TRUE,FALSE or NULL only.
3.DATE:
A user can enter a date in many different formats with
the TO_DATE function, but a date is always stored in
standard 7 byte format.
Century.
Year.
Month.
Day.
Hour.
Minute.
Second.
VARIABLE DECLARATION:
The declarations are done in the DECLARE section
of the program block.
Syntax:
DECLARE
identifier name[CONSTRAINT] datatype
[NOT NULL][:=DEFAULT expression]
ANCHORED DECLARATION:
SQL uses %TYPE attribute to anchor a variable’s data
type.
Syntax:
variablename typeattribute %TYPE [value assignment]
NESTED ANCHORING:
The %TYPE attribute’s use can be nested.
Syntax :
DECLARE
--source variable v _ commission
v _ commission NUMBER(7,2)
NOT NULL CONSTRAINT FOR %TYPE
DECLARATIONS:
If a source variable is declared with a NOT NULL
constraint , the %TYPE declaration inherits the NOT NULL
constraint from the source.
ASSIGNMENT OPERATION:
The assignment operation is one of the ways to assign
value to a variable.
Syntax:
Variablename := literal  variable name  expression;
BIND VARIABLES:
Bind variables are also known as host variables.
Syntax:
VARIABLE variablename datatype
ARITHMETIC OPERATORS:
Five standard arithmetic operators are available in SQL.
Arithmetic operator use
+ Addition
- Subtraction
* Multiplication
/ Division
** Exponentiation
Sequential structure.
Selection structure.
Looping structure.
CONTROL STRUCTURES:
Sequential structure:
A series of instructions are performed from the beginning
to the end in a linear order.
Selection structure:
There are three selection or conditional statements in
SQL.
 Relational operators.
 Logical operators.
 Special operators.
PL/SQL has five conditional or selection statement’s
available for decision making.
 IF…THEN…END IF.
 IF…THEN…ELSE…END IF.
 IF…THEN…ELSIF…END IF.
 CASE…END CASE.
 Searched CASE.
IF…THEN…END IF
It is also known as simple IF statement. A simple IF
statement performs action statements if the result of the
condition is TRUE. If the condition is FALSE, no action is
performed.
Syntax:
IF condition(s) THEN
Action statements
END IF;
IF…THEN…ELSE…END IF:
This statement is an extension of the simple IF statement.
It provides action statements for the TRUE outcome as well
as for the FALSE outcome.
Syntax:
IF condition(s) THEN
Action statement 1
ELSE
Action statement 2
END IF;
IF…THEN…ELSIF…END IF:
When you have many alternative /options, you can use
previously explained statements, but the ELSFIF alternative
is more efficient than the other two.
Syntax:
IF condition(s)1 THEN
Action statements 1
ELSIF condition(s)2 THEN
Action statements 2
…
ELSIF condition(s)N THEN
Action statement N
[ELSE
Else Action statements]
END IF;
CASE:
The CASE statement is an alternative to the IF…THEN…
ELSIF…END IF statement. The CASE statement begins
with keyword CASE and ends with the keywords END
CASE.
Syntax:
Case [variable_name]
WHEN value1condition1 THEN action_statement1;
WHEN value2condition2 THEN action_statement2;
WHEN valueNcondition N THEN action_statementN;
ELSE action_statement;
END CASE;
SEARCHED CASE:
A statement with a value is known as a CASE statement,
and a statement with conditions is known as a searched
CASE statement. A CASE statement uses variable_name as
a selector, but a searched CASE does not use variable_name
as a selector.
NESTED IF:
The nested IF statement contains an IF statement within
another IF statement. If the condition in the outer IF
statement is TRUE, the inner IF statement is performed.
Looping structure:
Looping means iterations. A loop repeats a statement or
series of statements a specific number of times as defined by
the programmer.
THREE TYPES
 Basic loop
 While loop
 For loop
BASIC LOOP
A basic loop is a loop that is performed repeatedly. once a
loop is entered all statements in the loop are performed.
Syntax
Loop
Looping statement 1;
Looping statement 2;
……….
Looping statement N;
Exit (when condition);
End loop
WHILE LOOP
The while loop is an alternative to be basic loop and it
performed as long as the condition is true terminates the
condition becomes false.
Syntax
While condition loop
Looping statement 1;
Looping statement 2;
…….
Looping structure n;
End loop;
FOR LOOP
The for loop is the simples loop you can write. There is a
no net and no use an exit statement, And the counter need
not be declared.
Syntax
For counter in (reverse)lower….upper loop
Looping statement1
Looping statement2
……
Looping statement N
End loops
NESTED BLOCKS
PL/SQL block may contain another PL/SQL block ; in
another words PL/SQL blocks can be nested.
DATA MANIPULATION
 Insert statement
 Delete statement
 Update statement
INSERT STATEMENT
We will use an insert statement to add a new employee in
the employee table.
DELETE STATEMENT
We will show the use of the delete statement in the
PL/SQL block to remove some rows.
UPDATE STATEMENT
The update statement can be used in a PL/SQL block for
modification off data.
TRANSACTION CONTRAL STATEMENT
The COMMIT statements to commit the current
transaction.
The SAVEPOINT statements to mark a point in
your transaction.
The ROLLBACK (TO SAVEPOINT N)
statements to discard all or part of the transaction.

More Related Content

PPT
04 Handling Exceptions
PPT
1 - Introduction to PL/SQL
PPTX
SQL Functions
PPTX
Unix shell scripts
PPTX
PRESENTATION ON FOR LOOP
PPTX
Conditional statement c++
PPTX
Looping statement
PDF
Pl sql-ch1
04 Handling Exceptions
1 - Introduction to PL/SQL
SQL Functions
Unix shell scripts
PRESENTATION ON FOR LOOP
Conditional statement c++
Looping statement
Pl sql-ch1

What's hot (20)

PPTX
Stored procedure
PPT
Including Constraints -Oracle Data base
PDF
Exception handling in plsql
PPT
02 Writing Executable Statments
PPTX
Branching statements
PPT
Branching in C
PPTX
Forloop
PPT
Oracle PLSQL Step By Step Guide
PPTX
Function in PL/SQL
PPTX
PPT
Decision making and branching
PDF
C++ goto statement tutorialspoint
PPTX
Scope rules : local and global variables
PPT
05 Creating Stored Procedures
PPTX
While , For , Do-While Loop
PPT
Oracle pl/sql control statments
PPTX
Inheritance in java
PPT
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
PPTX
Decision Making Statement in C ppt
PPTX
Unit 3. Input and Output
Stored procedure
Including Constraints -Oracle Data base
Exception handling in plsql
02 Writing Executable Statments
Branching statements
Branching in C
Forloop
Oracle PLSQL Step By Step Guide
Function in PL/SQL
Decision making and branching
C++ goto statement tutorialspoint
Scope rules : local and global variables
05 Creating Stored Procedures
While , For , Do-While Loop
Oracle pl/sql control statments
Inheritance in java
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
Decision Making Statement in C ppt
Unit 3. Input and Output
Ad

Similar to ORACLE PL/SQL (20)

PPTX
PL SQL.pptx in computer language in database
PDF
RDBMS - UNIT 4.pdf,UNIT THREE AND UNIT FIVE
PPT
Ppt on plssql study aboutnsmsmskskwkwkwkwk
PPTX
4. plsql
PPTX
Pl sql Prograaming of Database management system
PPTX
Ch as pbdasdadssadsadsadasdasdasdas fdt .pptx
PDF
DBMS 2011
PDF
Procedural Language/Structured Query Language
PPTX
PLSQL.pptx
PPT
pl_sql.ppt
PDF
Dbms 2011
PDF
B.Sc. II (IV Sem) RDBMS & PL/SQL Unit-5 PL/SQL, Cursor and Trigger
PPTX
Unit 4 plsql
PDF
rdbms.pdf plsql database system notes for students to study
PPT
SQL / PL
PPT
Oracle_PLSQL_basic_tutorial_with_workon_Exercises.ppt
PDF
UNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdf
PPTX
SQL Programming in database Management System
PDF
PL/SQL Complete Tutorial. All Topics Covered
PDF
PLSQL Note
PL SQL.pptx in computer language in database
RDBMS - UNIT 4.pdf,UNIT THREE AND UNIT FIVE
Ppt on plssql study aboutnsmsmskskwkwkwkwk
4. plsql
Pl sql Prograaming of Database management system
Ch as pbdasdadssadsadsadasdasdasdas fdt .pptx
DBMS 2011
Procedural Language/Structured Query Language
PLSQL.pptx
pl_sql.ppt
Dbms 2011
B.Sc. II (IV Sem) RDBMS & PL/SQL Unit-5 PL/SQL, Cursor and Trigger
Unit 4 plsql
rdbms.pdf plsql database system notes for students to study
SQL / PL
Oracle_PLSQL_basic_tutorial_with_workon_Exercises.ppt
UNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdf
SQL Programming in database Management System
PL/SQL Complete Tutorial. All Topics Covered
PLSQL Note
Ad

More from ASHABOOPATHY (13)

PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
MULTIPLE TABLES
PPTX
Orcal FUNCTIONS
PPTX
Oracel CURSOR AND EXCEPTIONS
PPTX
OrACLE RELATIONAL
PPTX
PPTX
Phpbase
MULTIPLE TABLES
Orcal FUNCTIONS
Oracel CURSOR AND EXCEPTIONS
OrACLE RELATIONAL
Phpbase

Recently uploaded (20)

PPTX
Cell Structure & Organelles in detailed.
PDF
Insiders guide to clinical Medicine.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Lesson notes of climatology university.
PDF
Basic Mud Logging Guide for educational purpose
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Cell Types and Its function , kingdom of life
PDF
Classroom Observation Tools for Teachers
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Institutional Correction lecture only . . .
PDF
Complications of Minimal Access Surgery at WLH
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Cell Structure & Organelles in detailed.
Insiders guide to clinical Medicine.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
TR - Agricultural Crops Production NC III.pdf
Lesson notes of climatology university.
Basic Mud Logging Guide for educational purpose
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
GDM (1) (1).pptx small presentation for students
Microbial diseases, their pathogenesis and prophylaxis
102 student loan defaulters named and shamed – Is someone you know on the list?
Computing-Curriculum for Schools in Ghana
Cell Types and Its function , kingdom of life
Classroom Observation Tools for Teachers
Renaissance Architecture: A Journey from Faith to Humanism
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Institutional Correction lecture only . . .
Complications of Minimal Access Surgery at WLH
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx

ORACLE PL/SQL

  • 1. PL/SQL: A PROGRAMMING LANGUAGE & CONTROL STRUCTURES
  • 2. PL/SQL: A PROGRAMMING LANGUAGE. The standard query language for relationship database is SQL (Structured query language ).structured query language is a fourth –generation , high level, nonprocedural language. The PL/SQL also possess features of object-oriented languages, such as: Data encapsulation. Error handling. Information hiding. Object-oriented programming(OOP).
  • 3. HISTORY OF PL/SQL  Built-in package.  Error handling.  The transaction control statements SAVEPOINT,ROLLBACK,AND COMMIT.  The DML statements INSERT,DELETE, AND UPDATE.  Built-in functions –character, numeric, conversion, and date functions.  Modular programming with procedures and functions.  Programmer- defined subtypes.  Stored procedures, functions, and packages.  DDL support through the DBMS –SQL package.  Database access through work areas called cursors.
  • 4. FUNDAMENTALS A PL/SQL program constants of statements . You may use upper or lowercase letters in your program. RESERVED WORDS IDENTIFIERS LITERALS COMMENTS RESERVED WORDS The reserved words or by words are words provided but the language that have a specific use in the language. Example –end , if while, package.
  • 5. IDENTIFIERS User –defined identifiers used to name variables, constants, procedures, functions cursors, tables, records and exception. RULES The name can be from 1to 30 characters in length. The name must start with a letter . Spaces are not allowed. Other special character are not allowed. LITERALS Literals are values that are not represented by user-defined identifiers.
  • 6. THREE TYPES of literals: Numeric Character Boolean PL/SQL BLOCK STRUTURE PL/SQL is a block structured language. A program can be dividend into logical blocks. TWO TYPES Anonymous block Named block
  • 7. 1.ANONYMOUS BLOCK An anonymous block is a block of code without a name. 2.NAMED BLOCK A subprogram is a named block that can be called and can take arguments. COMMENTS Comments are used to document program. They are written as part of a program but they are executed . In fact comments are ignored by the PL/SQL engine. 1.To write a single line comments two dashes(--)are entered at the beginning of a new line.
  • 8. EXAMPLE: --This is a single line comment 2.To write a multiline comment text is placed between /*and*/. A multiline comment can be written on a separate line . EXAMPLE: /*This is a multiline comment that ends here */
  • 11. 1.Character: Variables with a character data type can store text. The text may include letters , number & special characters. Character data type include ; CHAR. VARCHAR. 2.NUMBER: Whole numbers or integer values can be handled by following data types. BINARY INTEGER. INTEGER. INT. SMALLINT. POSITIVE. NATURAL.
  • 12. 2.BOOLEaN : It is used for Boolean data TRUE,FALSE or NULL only. 3.DATE: A user can enter a date in many different formats with the TO_DATE function, but a date is always stored in standard 7 byte format. Century. Year. Month. Day. Hour. Minute. Second.
  • 13. VARIABLE DECLARATION: The declarations are done in the DECLARE section of the program block. Syntax: DECLARE identifier name[CONSTRAINT] datatype [NOT NULL][:=DEFAULT expression]
  • 14. ANCHORED DECLARATION: SQL uses %TYPE attribute to anchor a variable’s data type. Syntax: variablename typeattribute %TYPE [value assignment] NESTED ANCHORING: The %TYPE attribute’s use can be nested. Syntax : DECLARE --source variable v _ commission v _ commission NUMBER(7,2)
  • 15. NOT NULL CONSTRAINT FOR %TYPE DECLARATIONS: If a source variable is declared with a NOT NULL constraint , the %TYPE declaration inherits the NOT NULL constraint from the source. ASSIGNMENT OPERATION: The assignment operation is one of the ways to assign value to a variable. Syntax: Variablename := literal variable name expression;
  • 16. BIND VARIABLES: Bind variables are also known as host variables. Syntax: VARIABLE variablename datatype ARITHMETIC OPERATORS: Five standard arithmetic operators are available in SQL. Arithmetic operator use + Addition - Subtraction * Multiplication / Division ** Exponentiation
  • 17. Sequential structure. Selection structure. Looping structure. CONTROL STRUCTURES:
  • 18. Sequential structure: A series of instructions are performed from the beginning to the end in a linear order. Selection structure: There are three selection or conditional statements in SQL.  Relational operators.  Logical operators.  Special operators. PL/SQL has five conditional or selection statement’s available for decision making.
  • 19.  IF…THEN…END IF.  IF…THEN…ELSE…END IF.  IF…THEN…ELSIF…END IF.  CASE…END CASE.  Searched CASE. IF…THEN…END IF It is also known as simple IF statement. A simple IF statement performs action statements if the result of the condition is TRUE. If the condition is FALSE, no action is performed.
  • 20. Syntax: IF condition(s) THEN Action statements END IF; IF…THEN…ELSE…END IF: This statement is an extension of the simple IF statement. It provides action statements for the TRUE outcome as well as for the FALSE outcome.
  • 21. Syntax: IF condition(s) THEN Action statement 1 ELSE Action statement 2 END IF; IF…THEN…ELSIF…END IF: When you have many alternative /options, you can use previously explained statements, but the ELSFIF alternative is more efficient than the other two.
  • 22. Syntax: IF condition(s)1 THEN Action statements 1 ELSIF condition(s)2 THEN Action statements 2 … ELSIF condition(s)N THEN Action statement N [ELSE Else Action statements] END IF;
  • 23. CASE: The CASE statement is an alternative to the IF…THEN… ELSIF…END IF statement. The CASE statement begins with keyword CASE and ends with the keywords END CASE. Syntax: Case [variable_name] WHEN value1condition1 THEN action_statement1; WHEN value2condition2 THEN action_statement2; WHEN valueNcondition N THEN action_statementN; ELSE action_statement; END CASE;
  • 24. SEARCHED CASE: A statement with a value is known as a CASE statement, and a statement with conditions is known as a searched CASE statement. A CASE statement uses variable_name as a selector, but a searched CASE does not use variable_name as a selector. NESTED IF: The nested IF statement contains an IF statement within another IF statement. If the condition in the outer IF statement is TRUE, the inner IF statement is performed.
  • 25. Looping structure: Looping means iterations. A loop repeats a statement or series of statements a specific number of times as defined by the programmer. THREE TYPES  Basic loop  While loop  For loop BASIC LOOP A basic loop is a loop that is performed repeatedly. once a loop is entered all statements in the loop are performed.
  • 26. Syntax Loop Looping statement 1; Looping statement 2; ………. Looping statement N; Exit (when condition); End loop WHILE LOOP The while loop is an alternative to be basic loop and it performed as long as the condition is true terminates the condition becomes false.
  • 27. Syntax While condition loop Looping statement 1; Looping statement 2; ……. Looping structure n; End loop; FOR LOOP The for loop is the simples loop you can write. There is a no net and no use an exit statement, And the counter need not be declared.
  • 28. Syntax For counter in (reverse)lower….upper loop Looping statement1 Looping statement2 …… Looping statement N End loops NESTED BLOCKS PL/SQL block may contain another PL/SQL block ; in another words PL/SQL blocks can be nested.
  • 29. DATA MANIPULATION  Insert statement  Delete statement  Update statement INSERT STATEMENT We will use an insert statement to add a new employee in the employee table. DELETE STATEMENT We will show the use of the delete statement in the PL/SQL block to remove some rows.
  • 30. UPDATE STATEMENT The update statement can be used in a PL/SQL block for modification off data. TRANSACTION CONTRAL STATEMENT The COMMIT statements to commit the current transaction. The SAVEPOINT statements to mark a point in your transaction. The ROLLBACK (TO SAVEPOINT N) statements to discard all or part of the transaction.