Académique Documents
Professionnel Documents
Culture Documents
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
<exception handling>
END;
PL/SQL - Data Types
CHAR ( MAX_LENGTH)
VARCHAR2 ( MAX LENGTH)
NUMBER (PRECISION, SCALE)
BINARY_INTEGER
RAW
DATE
BOOLEAN
PL/SQL VARIABLES
EXAM PLE
LOOP DECLARE
Sequence of statements;
x number := 10;
END LOOP;
BEGIN LOOP
dbms_output.put_line(x);
x := x + 10;
IF x > 50 THEN exit;
END IF;
END LOOP;
dbms_output.put_line
('After Exit x is: ' || x);
END;
WHILE LOOP STRUCTURE & EXAMPLE :
a := a + 1;
END LOOP;
END;
FOR LOOP STRUCTURE & EXAMPLE :
FOR counter IN
initial_value .. final_value DECLARE
LOOP a number(2);
sequence_of_statements;
END LOOP; BEGIN
FOR a in 10 .. 20
LOOP
END LOOP;
END;
PROCEDURES
OUT : An OUT parameter returns a value to the calling program. Inside the
subprogram, an OUT parameter acts like a variable. The actual parameter
must be a variable and it is passed by a value.
CREATING PROCEDURE :
CREATE OR REPLACE PROCEDURE PROCEDURE_NAME
AS
BEGIN
dbms_output.put_line(‘STATEMENTS’)
END;
EXECUTE : EXECUTE PROCEDUR
; DROP : DROP PROCEDURE PROCEDURE_NAME .
FUNCTION
Functions − These subprograms return a single value; mainly used to
compute and return a value.
Creating a Function : A standalone function is created using the CREATE
FUNCTION statement. The basic syntax of creating a function is :
The oracle engine uses a work area for its internal processing in order to
execute an SQL statement. This work is private to SQL operations and is
called a cursor. The set of rows the cursor holds is referred to as the active
set.
There are 2 types of cursor.
1. Implicit cursor
2. Explicit cursor
Implicit cursor and attributes
Implicit cursor is automatically created when a query or manipulation is for
a single row.
Attributes Description
DECLARE
total_rows number(2);
BEGIN
UPDATE table_name
statements
IF sql%notfound THEN
dbms_output.put_line(‘statements');
ELSIF sql%found THEN
total_rows := sql%rowcount;
dbms_output.put_line( total_rows || ' statement ');
END IF;
END;
Explicit cursor
The specification is the interface to the package. It just DECLARES the types,
variables, constants, exceptions, cursors, and subprograms that can be
referenced from outside the package.
Syntax to create a package :
CREATE OR REPLACE PACKAGE package_name AS
PROCEDURE procedure_name (statement);
END package_name;
PACKAGE BODY:
The package body has the codes for various methods declared in the
package specification and other private declarations, which are hidden
from the code outside the package.
he basic syntax of package body is :
BEGIN
Initialization statements
End package_name;
GUIDELINES FOR WRITING PACKAGES :
THANK YOU