Advance Database Management System: Unit - 2 - Procedural Language/Structured Query Language (PL/SQL)
Advance Database Management System: Unit - 2 - Procedural Language/Structured Query Language (PL/SQL)
Management System
Unit – 2 . Procedural Language/Structured Query language (PL/SQL)
.
Index
▪ Introduction to PL/SQL
▪ Disadvantages of SQL and advantages of PL/SQL
▪ PL/SQL block structure
▪ Block data types, Block variable declaration and exception handling
▪ Cursors and types of cursors
▪ Functions, Procedures and Triggers.
Introduction to PL/SQL
▪ The PL/SQL procedural extension language for SQL and the Oracle relational
database
▪ Has features of programming language.
▪ SQL command are included in procedure block
▪ PL/SQl code are executed by procedure statement executer and SQL command s
are executed by SQL statement executor
PL/SQL Block
DECLARE
message varchar2(20):= 'Hello, World!';
BEGIN
dbms_output.put_line(message);
END;
/
Advantages of PL/SQL
▪ SQL is the standard database language and PL/SQL is strongly integrated with
SQL. PL/SQL supports both static and dynamic SQL. Static SQL supports DML
operations and transaction control from PL/SQL block.
▪ In Dynamic SQL, SQL allows embedding DDL statements in PL/SQL
blocks.PL/SQL allows sending an entire block of statements to the database at one
time. This reduces network traffic and provides high performance for the
applications.
▪ PL/SQL gives high productivity to programmers as it can query, transform, and
update data in a database.
▪ PL/SQL saves time on design and debugging by strong features, such as exception
handling, encapsulation, data hiding, and object-oriented data types.
Advantages of PL/SQL
▪ The BOOLEAN data type stores logical values that are used in logical
operations. The logical values are the Boolean values TRUE and
FALSE and the value NULL.
▪ However, SQL has no data type equivalent to BOOLEAN. Therefore,
Boolean values cannot be used in −
▪ SQL statements
▪ Built-in SQL functions (such as TO_CHAR)
▪ PL/SQL functions invoked from SQL statements
PL/SQL Large Object (LOB) Data Types
▪ Large Object (LOB) data types refer to large data items such as text,
graphic images, video clips, and sound waveforms. LOB data types
allow efficient, random, piecewise access to this data. Following are
the predefined PL/SQL LOB data types −
PL/SQL Datetime and Interval Types
PL/SQL User-Defined Subtypes
▪ declare
var1 varchar2(20);
num1 number(10);
begin
var1:=‘welcome’;
num1:=1000;
dbms_output.put_line(‘Var := ' || var1);
dbms_output.put_line(‘num1 := ' || num1);
end;
/
PL/SQL statement to take value from
table and put in variable and display
it
▪ declare
name varchar2(20);
salary number(10,2);
begin
select FirstName,Salary into name, salary from employee where Employeeid=10;
dbms_output.put_line(‘Name := ' || name);
dbms_output.put_line(‘Salary := ' || salary);
end;
/
TYPE
ROWTYPE
Variable Declaration