• Save
Oracle: PLSQL Introduction
Upcoming SlideShare
Loading in...5
×
 

Oracle: PLSQL Introduction

on

  • 2,522 views

Oracle: PLSQL Introduction

Oracle: PLSQL Introduction

Statistics

Views

Total Views
2,522
Views on SlideShare
2,458
Embed Views
64

Actions

Likes
1
Downloads
0
Comments
0

3 Embeds 64

http://www.ustudy.in 56
http://ustudy.in 6
http://www.slideshare.net 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Oracle: PLSQL Introduction Oracle: PLSQL Introduction Presentation Transcript

  • 1
    Using ORACLE®
    Introduction to PL/SQL
  • DATA DEFINATION LANGUAGE
    Oracle Engine
    PL/SQL ENGINE:
    2
    PL/SQL stands for Procedural Extension to Structured Query Language.
    PL /SQL support is provided in Oracle from versions > 6;
    PL/SQL is used to provide users with the ability to use variables, loops , function etc in the database.
    SQL can be combined easily into the PL/SQL code .Since the PL/SQL program is processed by the PL/SQL Statement Executor ,it reduces the load on Oracle thus making it perform
    faster.
  • 3
    Anonymous Block
    PL/SQL uses a block structure hence making it easier to write and maintain code.
    PL/SQL provides us with the following:
    Variables and constants.
    Loops and conditional constructs.
    Functions and Procedure that enable code reusability.
    Exception handling .
    The Anonymous Block ,the basic PL/SQL code is as follows:
    <<label>>
    [ DECLARE ]
    TYPE / item / FUNCTION / PROCEDURE declarations or variables.
    BEGIN
    Statements (both SQL and PL/SQL)
    [ EXCEPTION ]
    EXCEPTION handlers to handle the exception
    END label;
  • 4
    Anonymous Block
    Let us write an example Anonymous block.
    DECLARE
    name varchar2[20];
    BEGIN
    name := ‘Larry’;
    DBMS_OUTPUT.PUT_LINE(‘The name is : ‘ || name);
    END
    The above anonymous block print the name ‘Larry'. Key points to be highlighted here are:
    The variable name must follow rules similar to that of declaring Tables in SQL and the data type with size be mentioned.
    The := operator is the assignment operator in PL/SQL.
    The DBMS_OUTPUT.PUT_LINE prints text enclosed in ( ) .Here we use a ‘||’ concatenation operator to join the string and variable.
  • 5
    Variables
    The various data types in PL/SQL are :
    LOB refers to large object. It could be of the type BINARY LARGE OBJECT (BLOB) or CHARACTER LARGE OBJECT (CLOB) to store image or audio in binary format (BLOB) or a text file (CLOB) up to the size of 4 GIGABYTES.
    BFILE refers to an external file to be stored in a database.
    A variable must be declared in the “DECLARE” block as:
    VARIABLE_NAME DATATYPE[SIZE];
    A variable may be initialized when declared (otherwise set to NULL)
    VARIABLE_NAME DATATYPE[SIZE]:= VALUE;
    We may also define a variable to not hold null values.
    VARIABLE_NAME DATATYPE[SIZE] NOT NULL := VALUE;
  • 6
    %TYPE and %ROWTYPE
    We can declare a variable to have a data type of any column or another variable using the
    %TYPE attribute which is prefixed with the table and column or variable name.
    SYNTAX:
    VARIABLE _NAME TABLE_NAME.COLUMN_NAME[VARIABLE_NAME]%TYPE ;
    EXAMPLE:
    name InfoTable.name%TYPE;
    The %ROWTYPE attribute is used to declare a variable to hold an entire row which is a collection of multiple columns of a table.
    SYNTAX:
    VARIABLE _NAME TABLE_NAME %ROWTYPE
    EXAMPLE:
    name InfoTable%ROWTYPE;
  • 7
    BIND/HOST VARIABLES
    Bind variables are the variables that are created in the host environment hence also called as host variable. The features of a bind variable are:
    Unlike normal variables the memory used by a bind variable is not cleared when the PL/SQL block execution is complete.
    Can be accessed outside the block by other PL/SQL and SQL code.
    Declared using a VARIABLE keyword and above the “DECLARE” block.
    While usage they are referred wit a prefixed : symbol
    SYNTAX:
    VARIABLE variable_name DATATYPE[SIZE];
    EXAMPLE:
    VARIABLE eage NUMBER;
    BEGIN
    SELECT age INTO :eage FROM InfoTable WHERE name = ‘bill’;
    END
    Only character array variables need to be given a size.
  • 8
    Substitution Variables
    We can either hard code the values of variable or accept the values from the user. To accept a value from the user , it has to be declared as a SUBSTITUTION VARIABLE. Substitution variables when used accept value from user.
    SYNTAX:
    VARIABLE variable_name DATATYPE[SIZE] := &variable_name;
    EXAMPLE :
    VARIABLE age NUMBER;
    DECLARE
    ename VARCHAR(20) := &ename;
    BEGIN
    SELECT age INTO eage FRM InfoTable WHERE name = ename;
    END;
  • THANK YOU
    9
    THANK YOU FOR VIEWING THIS PRESENTATION
    FOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING ,
    please visit:
    www.dataminingtools.net