PL/SQL
Features:
Block structure: block structure language.
Programs written as block.
Variables and constants: allows to declare
variables and constants.
Control structure:
Exception handling: allows to handle runtime
error. Whenever there is a pre-defined error
PL/SQL raises an exception automatically.
Modularity: allow processes to be divided
into different modules. Subprograms
called as procedures and functions are
defined.
Cursor: is a private SQL area used to
execute SQL stmts and store processing
infn.
Built in function
declare
Variable declaration
begin
Program execution
exception
Exception handling
End;
Program to add
declare
a number;
b number;
c number;
begin
a: = &a;
b:= &b;
c: =a+b;
dbms_output.put_line('The addition is ' ||c);
end;
%type: attribute provides the data type of
a variable. This particularly useful when
declaring variables the will hold db
values.
Eg: name Emp.ename%type;
%rowtype: A variable can be declared
with %rowtype that is equivalent to a row
of a table.
Emp_rec Emp%rowtype;
Assigning value to variable
Using assignment operator(:=)
Using select statement.
Syntax: select columname into variable
name from tablename;
Eg: select ename into name from emp;