PLSQL Introduction
PLSQL Introduction
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 benefits of PL/SQL Identify the different types of PL/SQL blocks Use iSQL*Plus as a development environment for PL/SQL Output messages in PL/SQL
What Is PL/SQL?
PL/SQL: Stands for Procedural Language extension to SQL Is Oracle Corporations standard data access language for relational databases Seamlessly integrates procedural constructs with SQL
PL/SQL Environment
Benefits of PL/SQL
Integration of procedural constructs with SQL Improved performance SQL 1 SQL 2 SQL IF...THEN SQL ELSE SQL END IF; SQL
Benefits of PL/SQL
Modularized program development Integration with Oracle tools Portability Exception handling
BEGIN (mandatory)
SQL statements PL/SQL statements
EXCEPTION (optional)
Actions to perform when errors occur
END; (mandatory)
Block Types
Anonymous [DECLARE]
Procedure
Function
PROCEDURE name FUNCTION name IS RETURN datatype IS BEGIN BEGIN BEGIN --statements --statements --statements RETURN value; [EXCEPTION] [EXCEPTION] [EXCEPTION]
END;
END;
END;
Program Constructs
Database Server Constructs Anonymous blocks Stored procedures or functions Stored packages Database triggers Object types
iSQL*Plus
Enable output in iSQL*Plus with the following command: SET SERVEROUTPUT ON Use a predefined Oracle package and its procedure: DBMS_OUTPUT.PUT_LINE
SET SERVEROUTPUT ON DBMS_OUTPUT.PUT_LINE(' The First Name of the Employee is ' || f_name);