Database Reference
In-Depth Information
Declaration section : Identifies, variables, cursors, and other objects are declared in this
section those are referenced in the execution and exception sections. It is optional
Example:
DECLARE fname lname
cost
VARCHAR2(30); VARCHAR2(30); NUMBER := 0;
Execution section : This section contains executable statements (SQL and PL/ SQL) that
allow user to manipulate the variables that have been declared in the declaration section. It
is compulsory section.
Example 1:
BEGIN
SELECT firstname, lastname
INTO fname, lname
FROM student
WHERE studentID = 163;
DBMS_OUTPUT.PUT_LINE ('Student name: '||fname|| ' '||lname); END;
Exception section : This section contains statements that are executed when a runtime er-
ror occurs within the block. Errors can occur due to syntax, logic or validation rule viola-
tion. It is optional section.
Example 2:
BEGIN
SELECT tname, lastname
INTO fname, lname
FROM Student
WHERE studentID = 163;
DBMS_OUTPUT.PUT_LINE ('Student name: '||fname|| ' '||lname); EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE (' no student found with '|| 'Student ID163'); END;
Search WWH ::




Custom Search