1 PL/SQLPL/SQL Declaring Variables Declaring Variables Declaring Variables Declaring Variables Writing Executable Statements Writing Executable Statements.

Slides:



Advertisements
Similar presentations
BD05/06 PL/SQL  Introduction  Structure of a block  Variables and types  Accessing the database  Control flow  Cursors  Exceptions  Procedures.
Advertisements

AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
PL/SQL. Introduction to PL/SQL PL/SQL is the procedure extension to Oracle SQL. It is used to access an Oracle database from various environments (e.g.
PL/SQL.
PL/SQL (Procedural Language extensions to SQL) Prepared by: Manoj Kathpalia Edited by: M V Ramakrishna.
Lecture-5 Though SQL is the natural language of the DBA, it suffers from various inherent disadvantages, when used as a conventional programming language.
Chapter 4B: More Advanced PL/SQL Programming
Chapter 4: Introduction to PL/SQL. 2 Lesson A Objectives After completing this lesson, you should be able to: Describe the fundamentals of the PL/SQL.
Introduction to PL/SQL
Introduction to PL/SQL Lecture 0 – Self Study Akhtar Ali.
Copyright  Oracle Corporation, All rights reserved. 4 Creating Functions.
Introduction to PL/SQL Chapter 9. Objectives Explain the need for PL/SQL Explain the benefits of PL/SQL Identify the different types of PL/SQL blocks.
Dr. James Dullea, CSC8490 Introduction to PL/SQLSlide 1 of 36 7From Prof. Dullea CSC8490 Introduction to PL/SQL Module 01-9 Revised: June 12, 2005 Dr.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
1 Introduction to PL/SQL. 2  Procedural programming language  Uses detailed instructions  Processes statements sequentially  Combines SQL commands.
SQL enables us to create, organize, retrieve and maintain data stored in database it does not provide the features which a typical programming language.
EE Copyright س Oracle Corporation, All rights reserved. ® Review of PL/SQL.
Lecture 4 PL/SQL language. PL/SQL – procedural SQL Allows combining procedural and SQL code PL/SQL code is compiled, including SQL commands PL/SQL code.
6 Copyright © 2009, Oracle. All rights reserved. Working with Composite Data Types.
Oracle10g Developer: PL/SQL Programming1 Objectives Programming fundamentals The PL/SQL block Define and declare variables Initialize variables The NOT.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 2 Basic PL/SQL Block Structures.
11 Copyright س Oracle Corporation, All rights reserved. ® Overview of PL/SQL.
L/O/G/O Introduction to PL/SQL Oracle Database 10g Develop PLSQL Program Units.
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
PL/SQL : INTRODUCTION. PL/SQL PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database language. With PL/SQL, you.
Chapter 4: Introduction to PL/SQL
Program with PL/SQL Lesson 5. Working with Composite Data Types.
Overview · What is PL/SQL · Advantages of PL/SQL · Basic Structure of a PL/SQL Block · Procedure · Function · Anonymous Block · Types of Block · Declaring.
LECTURE 1 INTRODUCTION TO PL/SQL Tasneem Ghnaimat.
PL / SQL By Mohammed Baihan. What is PL/SQL? PL/SQL stands for Procedural Language extension of SQL. PL/SQL is a combination of SQL along with the procedural.
Oracle PL/SQL. PL/SQL Originally modeled after ADA Originally modeled after ADA Created for Dept. of DefenseCreated for Dept. of Defense Allows expanded.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
PL/SQL Block Structure DECLARE - Optional Variables, cursors, user-defined exceptions BEGIN - Mandatory SQL Statements PL/SQL Statements EXCEPTIONS - Optional.
PL/SQL Declaring Variables PL/SQL Block Structure DECLARE (Optional) Variables, cursors, user-defined exceptions BEGIN (Mandatory) - SQL statements -
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
Database Application Development using PL/SQL Programming.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
Introduction to PL/SQL. Objectives  After completing this lesson, you should be able to do the following:  Explain the need for PL/SQL  Explain the.
Copyright  Oracle Corporation, All rights reserved. 16 Declaring Variables.
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
Variables and control statements in PL\SQL Chapter 10.
Chapter 16 Cursors and Exceptions. Chapter Objectives  Determine when an explicit cursor is required  Declare, open, and close an explicit cursor 
9 Copyright © 2004, Oracle. All rights reserved. Manipulating Large Objects.
Declaring PL/SQL Variables
PL/SQL INTRODUCTION.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Introduction to PL/SQL Francis Thottungal. The outline The basic PL/SQL code structure is : DECLARE -- optional, which declares and define variables,
Copyright  Oracle Corporation, All rights reserved. 20 Working with Composite Datatypes.
Lab 2 Writing PL/SQL Blocks CISB514 Advanced Database Systems.
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences Overview.
Introduction to PL/SQL N. Dimililer. About PL/SQL –PL/SQL is an extension to SQL with design features of programming languages. –Data manipulation and.
CS422 Principles of Database Systems Oracle PL/SQL Chengyu Sun California State University, Los Angeles.
1 Copyright © 2004, Oracle. All rights reserved. PL/SQL Programming Concepts: Review.
C LANGUAGE MULITPLE CHOICE QUESTION SET-2
Introduction to PL/SQL
PL/SQL Declaring Variables Writing Executable Statements
CS322: Database Systems PL/ SQL PL/SQL by Ivan Bayross.
Declaring Variables Schedule: Timing Topic 45 minutes Lecture
Oracle11g: PL/SQL Programming Chapter 2 Basic PL/SQL Block Structures.
Working with Composite Datatypes
Chapter 4: Introduction to PL/SQL
variables and control statements in PL\SQL
Database Management Systems 2
PL/SQL week10.
Chapter 8 Advanced SQL.
PL/SQL Declaring Variables.
MATERI PL/SQL Procedures Functions Packages Database Triggers
Presentation transcript:

1 PL/SQLPL/SQL Declaring Variables Declaring Variables Declaring Variables Declaring Variables Writing Executable Statements Writing Executable Statements Writing Executable Statements Writing Executable Statements Interacting with the Oracle Server Interacting with the Oracle Server Interacting with the Oracle Server Interacting with the Oracle Server Writing Control Structures Writing Control Structures Writing Control Structures Writing Control Structures Working with Composite Datatypes Working with Composite Datatypes Working with Composite Datatypes Working with Composite Datatypes Cursors Cursors Cursors Handling Exceptions Handling Exceptions Handling Exceptions Handling Exceptions Declaring Variables Declaring Variables Declaring Variables Declaring Variables Writing Executable Statements Writing Executable Statements Writing Executable Statements Writing Executable Statements Interacting with the Oracle Server Interacting with the Oracle Server Interacting with the Oracle Server Interacting with the Oracle Server Writing Control Structures Writing Control Structures Writing Control Structures Writing Control Structures Working with Composite Datatypes Working with Composite Datatypes Working with Composite Datatypes Working with Composite Datatypes Cursors Cursors Cursors Handling Exceptions Handling Exceptions Handling Exceptions Handling Exceptions

2 ObjectivesObjectives After completing this lesson, you should be able to do the following: After completing this lesson, you should be able to do the following: List the benefits of PL/SQL List the benefits of PL/SQL Recognize the basic PL/SQL block and its sections Recognize the basic PL/SQL block and its sections Describe the significance of variables in PL/SQL Describe the significance of variables in PL/SQL Declare PL/SQL variables Declare PL/SQL variables Execute a PL/SQL block Execute a PL/SQL block After completing this lesson, you should be able to do the following: After completing this lesson, you should be able to do the following: List the benefits of PL/SQL List the benefits of PL/SQL Recognize the basic PL/SQL block and its sections Recognize the basic PL/SQL block and its sections Describe the significance of variables in PL/SQL Describe the significance of variables in PL/SQL Declare PL/SQL variables Declare PL/SQL variables Execute a PL/SQL block Execute a PL/SQL block

3 About PL/SQL PL/SQL is an extension to SQL with design features of programming languages. PL/SQL is an extension to SQL with design features of programming languages. Data manipulation and query statements of SQL are included within procedural units of code. Data manipulation and query statements of SQL are included within procedural units of code. PL/SQL not case sensitive language PL/SQL not case sensitive language A semicolon ; must end each PL/SQL command A semicolon ; must end each PL/SQL command PL/SQL is an extension to SQL with design features of programming languages. PL/SQL is an extension to SQL with design features of programming languages. Data manipulation and query statements of SQL are included within procedural units of code. Data manipulation and query statements of SQL are included within procedural units of code. PL/SQL not case sensitive language PL/SQL not case sensitive language A semicolon ; must end each PL/SQL command A semicolon ; must end each PL/SQL command

4 Benefits of PL/SQL Integration Integration Application Oracle Server Sharedlibrary

5 Benefits of PL/SQL Application Other DBMSs Application Oracle with PL/SQL SQL SQL SQL SQL SQLIF...THENSQLELSESQL END IF; SQL Improve performance Improve performance

6 PL/SQL Block Structure DECLARE – Optional Variables, cursors, user-defined exceptions BEGIN – Mandatory – SQL statements – PL/SQL statements EXCEPTION – Optional Actions to perform when errors occur END; – Mandatory DECLARE – Optional Variables, cursors, user-defined exceptions BEGIN – Mandatory – SQL statements – PL/SQL statements EXCEPTION – Optional Actions to perform when errors occur END; – Mandatory DECLARE BEGIN EXCEPTION END;

7 PL/SQL Block Structure DECLARE v_variable VARCHAR2(5); BEGIN SELECTcolumn_name INTOv_variable FROMtable_name; EXCEPTION WHEN exception_name THEN... END; DECLARE v_variable VARCHAR2(5); BEGIN SELECTcolumn_name INTOv_variable FROMtable_name; EXCEPTION WHEN exception_name THEN... END; DECLARE BEGIN EXCEPTION END;

8 Block Types AnonymousProcedureFunction AnonymousProcedureFunction [DECLARE]BEGIN --statements --statements[EXCEPTION]END;[DECLARE]BEGIN [EXCEPTION]END; PROCEDURE name ISBEGIN --statements --statements[EXCEPTION]END; PROCEDURE name ISBEGIN --statements --statements[EXCEPTION]END; FUNCTION name RETURN datatype ISBEGIN --statements --statements RETURN value; RETURN value;[EXCEPTION]END; FUNCTION name RETURN datatype ISBEGIN --statements --statements RETURN value; RETURN value;[EXCEPTION]END; These blocks can be entirely separate or nested one within another. Anonymous blocks are unnamed blocks. Subprograms are named PL/SQL blocks that can take parameters and can be invoked. These blocks can be entirely separate or nested one within another. Anonymous blocks are unnamed blocks. Subprograms are named PL/SQL blocks that can take parameters and can be invoked.

9 Program Constructs Anonymous block Application trigger Stored procedure/ function Database trigger Application procedure/ function Packaged procedure/ function function DECLARE BEGIN EXCEPTION END;

10 Declaring Variables

11 Use of Variables Use variables for: Use variables for: Temporary storage of data Temporary storage of data Manipulation of stored values Manipulation of stored values Reusability Reusability Ease of maintenance Ease of maintenance Use variables for: Use variables for: Temporary storage of data Temporary storage of data Manipulation of stored values Manipulation of stored values Reusability Reusability Ease of maintenance Ease of maintenance

12 Handling Variables in PL/SQL Declare and initialize variables in the declaration section. Declare and initialize variables in the declaration section. When you declare variable, the variables default value is always NULL When you declare variable, the variables default value is always NULL Assign new values to variables in the executable section. Assign new values to variables in the executable section. Pass values into PL/SQL blocks through parameters. Pass values into PL/SQL blocks through parameters. View results through output variables. View results through output variables. Declare and initialize variables in the declaration section. Declare and initialize variables in the declaration section. When you declare variable, the variables default value is always NULL When you declare variable, the variables default value is always NULL Assign new values to variables in the executable section. Assign new values to variables in the executable section. Pass values into PL/SQL blocks through parameters. Pass values into PL/SQL blocks through parameters. View results through output variables. View results through output variables.

13 TRUE Types of Variables 25-OCT OCT-99 Atlanta “ Four score and seven years ago our fathers brought forth upon this continent, a new nation, conceived in LIBERTY, and dedicated to the proposition that all men are created equal. ”

14 Types of Variables The slide illustrates the following variable datatypes: The slide illustrates the following variable datatypes: TRUE represents a Boolean value. TRUE represents a Boolean value. 25-OCT-99 represents a DATE. 25-OCT-99 represents a DATE. The photograph represents a BLOB. The photograph represents a BLOB. The text of a speech represents a LONG RAW. The text of a speech represents a LONG RAW represents a NUMBER datatype with precision and scale represents a NUMBER datatype with precision and scale. The movie represents a BFILE. The movie represents a BFILE. The city name represents a VARCHAR2. The city name represents a VARCHAR2.

15 Types of Variables PL/SQL variables: PL/SQL variables: Scalar Scalar Composite Composite Reference Reference LOB (large objects) LOB (large objects) Non-PL/SQL variables: Bind and host variables Non-PL/SQL variables: Bind and host variables PL/SQL variables: PL/SQL variables: Scalar Scalar Composite Composite Reference Reference LOB (large objects) LOB (large objects) Non-PL/SQL variables: Bind and host variables Non-PL/SQL variables: Bind and host variables

16 Types of Variables - scalar All PL/SQL variables have a datatype, which specifies a storage format, constraints, and valid range of values. All PL/SQL variables have a datatype, which specifies a storage format, constraints, and valid range of values. Scalar datatypes hold a single value. Scalar datatypes hold a single value. The main datatypes are those that correspond to column types. The main datatypes are those that correspond to column types. PL/SQL also supports Boolean variables. PL/SQL also supports Boolean variables. All PL/SQL variables have a datatype, which specifies a storage format, constraints, and valid range of values. All PL/SQL variables have a datatype, which specifies a storage format, constraints, and valid range of values. Scalar datatypes hold a single value. Scalar datatypes hold a single value. The main datatypes are those that correspond to column types. The main datatypes are those that correspond to column types. PL/SQL also supports Boolean variables. PL/SQL also supports Boolean variables.

17 Types of Variables - scalar

18 Declaring PL/SQL Variables SyntaxExamplesSyntaxExamples identifier [CONSTANT] datatype [NOT NULL] [:= | DEFAULT expr]; identifier [CONSTANT] datatype [NOT NULL] [:= | DEFAULT expr]; Declare v_hiredateDATE; v_deptnoNUMBER(2) NOT NULL := 10; v_locationVARCHAR2(13) := 'Atlanta'; c_commCONSTANT NUMBER := 1400; Declare v_hiredateDATE; v_deptnoNUMBER(2) NOT NULL := 10; v_locationVARCHAR2(13) := 'Atlanta'; c_commCONSTANT NUMBER := 1400;

19 Declaring PL/SQL Variables Guidelines Guidelines Follow naming conventions. Follow naming conventions. Initialize variables designated as NOT NULL and CONSTANT. Initialize variables designated as NOT NULL and CONSTANT. Initialize identifiers by using the assignment operator (:=) or the DEFAULT reserved word. Initialize identifiers by using the assignment operator (:=) or the DEFAULT reserved word. Declare at most one identifier per line. Declare at most one identifier per line. Guidelines Guidelines Follow naming conventions. Follow naming conventions. Initialize variables designated as NOT NULL and CONSTANT. Initialize variables designated as NOT NULL and CONSTANT. Initialize identifiers by using the assignment operator (:=) or the DEFAULT reserved word. Initialize identifiers by using the assignment operator (:=) or the DEFAULT reserved word. Declare at most one identifier per line. Declare at most one identifier per line.

20 Naming Rules Two variables can have the same name, provided they are in different blocks. Two variables can have the same name, provided they are in different blocks. The variable name (identifier) should not be the same as the name of table columns used in the block. The variable name (identifier) should not be the same as the name of table columns used in the block. Two variables can have the same name, provided they are in different blocks. Two variables can have the same name, provided they are in different blocks. The variable name (identifier) should not be the same as the name of table columns used in the block. The variable name (identifier) should not be the same as the name of table columns used in the block. DECLARE empnoNUMBER(4); BEGIN SELECTempno INTOempno FROMemp WHERE ename = 'SMITH'; END; DECLARE empnoNUMBER(4); BEGIN SELECTempno INTOempno FROMemp WHERE ename = 'SMITH'; END; Adopt a naming convention for PL/SQL identifiers: for example, v_empno Adopt a naming convention for PL/SQL identifiers: for example, v_empno

21 Variable Initialization and Keywords Using: Using: Assignment operator (:=) Assignment operator (:=) DEFAULT keyword DEFAULT keyword NOT NULL constraint NOT NULL constraint Using: Using: Assignment operator (:=) Assignment operator (:=) DEFAULT keyword DEFAULT keyword NOT NULL constraint NOT NULL constraint

22 Assigning Values to Variables v_ename := 'Maduro'; v_hiredate := '31-DEC-98'; SyntaxExamples Set a predefined hiredate for new employees. SyntaxExamples Set the employee name to Maduro. identifier := expr;

23 Scalar Datatypes Hold a single value Have no internal components Hold a single value Have no internal components 25-OCT OCT-99 Atlanta TRUE

24 Base Scalar Datatypes VARCHAR2 (maximum_length) VARCHAR2 (maximum_length) NUMBER [(precision, scale)] NUMBER [(precision, scale)] DATE DATE CHAR [(maximum_length)] CHAR [(maximum_length)] LONG LONG BOOLEAN BOOLEAN BINARY_INTEGER BINARY_INTEGER VARCHAR2 (maximum_length) VARCHAR2 (maximum_length) NUMBER [(precision, scale)] NUMBER [(precision, scale)] DATE DATE CHAR [(maximum_length)] CHAR [(maximum_length)] LONG LONG BOOLEAN BOOLEAN BINARY_INTEGER BINARY_INTEGER

25 Scalar Variable Declarations v_jobVARCHAR2(9); v_countBINARY_INTEGER := 0; v_total_salNUMBER(9,2) := 0; v_orderdateDATE := SYSDATE + 7; c_tax_rateCONSTANT NUMBER(3,2) := 8.25; v_validBOOLEAN NOT NULL := TRUE; v_jobVARCHAR2(9); v_countBINARY_INTEGER := 0; v_total_salNUMBER(9,2) := 0; v_orderdateDATE := SYSDATE + 7; c_tax_rateCONSTANT NUMBER(3,2) := 8.25; v_validBOOLEAN NOT NULL := TRUE; Examples Examples

26 Types of Variables – Reference Directly reference specific database column or row Directly reference specific database column or row Assume data type of associated column or row Assume data type of associated column or row %TYPE data declaration syntax: %TYPE data declaration syntax: var_name tablename.fieldname%TYPE; var_name tablename.fieldname%TYPE; %ROWTYPE data declaration syntax: %ROWTYPE data declaration syntax: variable_name tablename%ROWTYPE; variable_name tablename%ROWTYPE; Directly reference specific database column or row Directly reference specific database column or row Assume data type of associated column or row Assume data type of associated column or row %TYPE data declaration syntax: %TYPE data declaration syntax: var_name tablename.fieldname%TYPE; var_name tablename.fieldname%TYPE; %ROWTYPE data declaration syntax: %ROWTYPE data declaration syntax: variable_name tablename%ROWTYPE; variable_name tablename%ROWTYPE;

27 The %TYPE Attribute Declare a variable according to: Declare a variable according to: A database column definition A database column definition Another previously declared variable Another previously declared variable Prefix %TYPE with: Prefix %TYPE with: The database table and column The database table and column The previously declared variable name The previously declared variable name Declare a variable according to: Declare a variable according to: A database column definition A database column definition Another previously declared variable Another previously declared variable Prefix %TYPE with: Prefix %TYPE with: The database table and column The database table and column The previously declared variable name The previously declared variable name

28 Declaring Variables with the %TYPE Attribute Examples Examples... v_enameemp.ename%TYPE; v_balanceNUMBER(7,2); v_min_balancev_balance%TYPE := 10;... v_enameemp.ename%TYPE; v_balanceNUMBER(7,2); v_min_balancev_balance%TYPE := 10;...

29 Declaring Boolean Variables Only the values TRUE, FALSE, and NULL can be assigned to a Boolean variable. Only the values TRUE, FALSE, and NULL can be assigned to a Boolean variable. The variables are connected by the logical operators AND, OR, and NOT. The variables are connected by the logical operators AND, OR, and NOT. The variables always yield TRUE, FALSE, or NULL. The variables always yield TRUE, FALSE, or NULL. Arithmetic, character, and date expressions can be used to return a Boolean value. Arithmetic, character, and date expressions can be used to return a Boolean value. Only the values TRUE, FALSE, and NULL can be assigned to a Boolean variable. Only the values TRUE, FALSE, and NULL can be assigned to a Boolean variable. The variables are connected by the logical operators AND, OR, and NOT. The variables are connected by the logical operators AND, OR, and NOT. The variables always yield TRUE, FALSE, or NULL. The variables always yield TRUE, FALSE, or NULL. Arithmetic, character, and date expressions can be used to return a Boolean value. Arithmetic, character, and date expressions can be used to return a Boolean value.

SMITH 2JONES 3NANCY 4TIM PL/SQL table structure BINARY_INTEGER VARCHAR2 BINARY_INTEGER NUMBER PL/SQL Record Structure TRUE 23-DEC-98ATLANTA

31 LOB Datatype Variables Book(CLOB) Photo(BLOB) Movie(BFILE) NCLOB

32 Displaying PL/SQL Program Output in SQL*Plus PL/SQL output buffer PL/SQL output buffer Memory area on database server Memory area on database server Stores program’s output values before they are displayed to user Stores program’s output values before they are displayed to user Should increase size Should increase size SET SERVEROUTPUT ON SIZE buffer_size SET SERVEROUTPUT ON SIZE buffer_size Default buffer size Default buffer size 2000 bytes 2000 bytes

33 Displaying PL/SQL Program Output in SQL*Plus (continued) Display program output Display program output DBMS_OUTPUT.PUT_LINE('display_te xt'); Display maximum of 255 characters of text data Display maximum of 255 characters of text data

34 Writing a PL/SQL Program Write PL/SQL program in Notepad or another text editor Write PL/SQL program in Notepad or another text editor Copy and paste program commands into SQL*Plus Copy and paste program commands into SQL*Plus Press Enter after last program command Press Enter after last program command Type front slash ( / ) Type front slash ( / ) Then press Enter again Then press Enter again

35 DBMS_OUTPUT.PUT_LINEDBMS_OUTPUT.PUT_LINE An Oracle-supplied packaged procedure An Oracle-supplied packaged procedure An alternative for displaying data from a PL/SQL block An alternative for displaying data from a PL/SQL block Must be enabled in SQL*Plus with SET SERVEROUTPUT ON Must be enabled in SQL*Plus with SET SERVEROUTPUT ON An Oracle-supplied packaged procedure An Oracle-supplied packaged procedure An alternative for displaying data from a PL/SQL block An alternative for displaying data from a PL/SQL block Must be enabled in SQL*Plus with SET SERVEROUTPUT ON Must be enabled in SQL*Plus with SET SERVEROUTPUT ON

36 PL/SQL Program Commands

37 SummarySummary PL/SQL blocks are composed of the following sections: PL/SQL blocks are composed of the following sections: Declarative (optional) Declarative (optional) Executable (required) Executable (required) Exception handling (optional) Exception handling (optional) A PL/SQL block can be an anonymous block, procedure, or function. A PL/SQL block can be an anonymous block, procedure, or function. PL/SQL blocks are composed of the following sections: PL/SQL blocks are composed of the following sections: Declarative (optional) Declarative (optional) Executable (required) Executable (required) Exception handling (optional) Exception handling (optional) A PL/SQL block can be an anonymous block, procedure, or function. A PL/SQL block can be an anonymous block, procedure, or function. DECLARE BEGIN EXCEPTION END;

38 SummarySummary PL/SQL identifiers: PL/SQL identifiers: Are defined in the declarative section Are defined in the declarative section Can be of scalar, composite, reference, or LOB datatype Can be of scalar, composite, reference, or LOB datatype Can be based on the structure of another variable or database object Can be based on the structure of another variable or database object Can be initialized Can be initialized PL/SQL identifiers: PL/SQL identifiers: Are defined in the declarative section Are defined in the declarative section Can be of scalar, composite, reference, or LOB datatype Can be of scalar, composite, reference, or LOB datatype Can be based on the structure of another variable or database object Can be based on the structure of another variable or database object Can be initialized Can be initialized