PL/SQL (Procedural Language extensions to SQL) Prepared by: Manoj Kathpalia Edited by: M V Ramakrishna.

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.
INTRODUCTION TO ORACLE Lynnwood Brown System Managers LLC Introduction to PL/SQL – Lecture 6.
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
PL/SQL Agenda: Basic PL/SQL block structure
Oracle PL/SQL Eyad Husni Elshami. Why PL/SQL Block Structures: – PL/SQL consists of blocks of code, which can be nested within each other. Each block.
PL/SQL The Oracle Programming Language. Purpose SQL is a non-procedural language. Often we need to put structure on transactions, so we use the supplemental.
Introduction to PL/SQL
Objectives Why PL-SQL ? Language features
PL/SQL Introduction Database 1. Practice. Sample Database The schema of the sample database is the following: Drinkers (name, occupation, birthday, salary)
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.
Introduction to PL/SQL. Procedural Language extension for SQL Oracle Proprietary 3GL Capabilities Integration of SQL Portable within Oracle data bases.
Session Title: Using SQL and PL/SQL for Queries and Reporting Presented By: Stephen Frederic Institution: IHL September 16, 2013.
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.
Benefits of PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –List and explain the benefits of PL/SQL –List.
SQL enables us to create, organize, retrieve and maintain data stored in database it does not provide the features which a typical programming language.
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.
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.
Overview · What is PL/SQL · Advantages of PL/SQL · Basic Structure of a PL/SQL Block · Procedure · Function · Anonymous Block · Types of Block · Declaring.
Session Title: Using SQL and PL/SQL for Queries and Reporting Presented By: Stephen Frederic Institution: IHL September 16, 2014.
LECTURE 1 INTRODUCTION TO PL/SQL Tasneem Ghnaimat.
CS178 Database Management PL/SQL session 8 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman.
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.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
CIS4368: Advanced DatabaseSlide # 1 PL/SQL Dr. Peeter KirsSpring, 2003 PL/SQL.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
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.
PL/SQL. Introduction to PL/SQL block Declare declarations Begin executable statement Exception exception handlers End;
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.
Database Management COP4540, SCS, FIU Oracle PL/SQL (Ch 10.5)
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
1 PL/SQLPL/SQL Declaring Variables Declaring Variables Declaring Variables Declaring Variables Writing Executable Statements Writing Executable Statements.
Copyright  Oracle Corporation, All rights reserved. 16 Declaring Variables.
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
Chapter 16 Cursors and Exceptions. Chapter Objectives  Determine when an explicit cursor is required  Declare, open, and close an explicit cursor 
A Guide to SQL, Eighth Edition Chapter Eight SQL Functions and Procedures.
Declaring PL/SQL Variables
Introduction to PL/SQL As usual, use speaker notes for additional information!
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,
Lab 2 Writing PL/SQL Blocks CISB514 Advanced Database Systems.
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.
8 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
CS422 Principles of Database Systems Oracle PL/SQL Chengyu Sun California State University, Los Angeles.
DB Programming Course Lecture 4. Errors Two types of errors can be found in a program: compilation errors and runtime errors. There is a special section.
PLSQL Cont…. Most Common Oracle Data Types VARCHAR2 –Stores variable-length character data. –Takes a required parameter that specifies a maximum length.
Pl/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-3
PL/pgSQL
SQL and SQL*Plus Interaction
Creating Stored Procedures and Functions
PL/SQL.
Oracle11g: PL/SQL Programming Chapter 2 Basic PL/SQL Block Structures.
SQL PL/SQL Presented by: Dr. Samir Tartir
PL / SQL Basics Chapter 3.
Agenda Summary of last class Cursors Loops Records Simple Loops
Chapter 4: Introduction to PL/SQL
PL/SQL week10.
Chapter 8 Advanced SQL.
PL/SQL Declaring Variables.
MATERI PL/SQL Procedures Functions Packages Database Triggers
Presentation transcript:

PL/SQL (Procedural Language extensions to SQL) Prepared by: Manoj Kathpalia Edited by: M V Ramakrishna

Outline Purpose of PL/SQL. PL/SQL block, its structure and types. PL/SQL Syntax.

Purpose of PL/SQL Procedural programming language used to access an Oracle database. Designed to overcome SQL's inability to handle control aspects of database interaction. Extends SQL by adding procedural language constructs, such as: - Variables and types.

- Control structures (IF-THEN-ELSE statements and loops). - Procedures and functions. Procedural constructs are integrated seamlessly with Oracle SQL, resulting in a structured, powerful language. Well-suited for designing complex applications.

PL/SQL Block Block is a basic unit in PL/SQL. All PL/SQL programs consist of blocks and each block performs a logical function in the program. Blocks can be nested within each other or can occur sequentially.

PL/SQL Block Structure DECLARE (Declarative section) BEGIN (Executable section) EXCEPTION (Exception handling section) END; / (/ at the end of a block tells Oracle to run the block)

Types of PL/SQL Blocks as Anonymous blocks which are compiled and run when loaded. as Triggers to maintain integrity. as Subprograms (Procedures and Functions) stored within the database that can be executed many times. as Packages, a named declarative section for storing related objects that can include procedures, functions and variables.

PL/SQL Syntax Declaration Variables are declared in the declarative section of the block. Variable declaration examples: v_student_id CHAR(8); v_lastname VARCHAR2(25); v_capacity NUMBER(3) := 200; ( := is used to initialize variables )

Types Basic PL/SQL types are: NUMBER(P,S) holds numeric value (where P is the precision and S is the scale) VARCHAR2(L) holds strings or character data (where L is the maximum length of the variable) CHAR(L) for fixed-length character strings DATE for storing date and time information BOOLEAN can hold TRUE, FALSE or NULL only

Declaring variables with %TYPE attribute %TYPE attribute is used when a PL/SQL variable is going to be used to manipulate the data stored in the database. The variable should have the same type as the table column (field). Specifying %TYPE attribute takes care.

For example, if the variable is used in the PL/SQL program to store the phone number of a student, following declaration can be used v_phone STUDENT.phone%TYPE; Instead of, say v_phone CHAR(10);

PL/SQL Syntax Control Structures IF-THEN-ELSE IF boolean_expression1 THEN sequence_of_statements1; [ELSIF boolean_expression2 THEN sequence_of_statements2; ] … [ELSE sequence_of_statements3; ] END IF;

LOOPS Simple Loops LOOP sequence_of_statements; END LOOP; EXIT [WHEN condition ]; is used to exit the loop

WHILE Loops WHILE condition LOOP sequence_of_statements; END LOOP: EXIT or EXIT WHEN will also be used to exit the loop

FOR Loops FOR loop_counter IN [REVERSE] low_bound.. high_bound LOOP sequence_of_statements; END LOOP:

Comments Single-line comments DECLARE v_title CHAR(2) -- title can be Mr or Ms … Multi-line comments DECLARE /* I am a multi-line comment */

-- Command to display the output at the SQL prompt SET SERVEROUTPUT ON -- This PL/SQL block accepts a number from the terminal, and prints out its square. -- You can try this from sql+ -- It has no exception handling code. DECLARE num1 NUMBER(3); num1_sq NUMBER(6); BEGIN -- prompts user for a value for 'anytemp' num1 := &anytemp; num1_sq := num1 * num1 ; DBMS_OUTPUT.PUT_LINE('THE SQUARE OF ' || num1 || ' IS ' || num1_sq); END; /