Documente Academic
Documente Profesional
Documente Cultură
Declare
Declaration statements
BEGIN
Executable statements
EXCEPTION
Exception-Handling Statements
END;
DECLARATION SECTION
It contains definitions of PL/SQL identifiers such as variables, constant, cursors and so on.
For Example
DECLARE
v_first_name varchar2(35);
v_last_name varchar2(35);
EXECUTABLE SECTION
This section contains executable statements that allow you to manipulate the variables that have been
declared in the declaration section.
For Example
BEGIN
FROM student
END;
EXCEPTION-HANDLING SECTION
This section contains statements that are executed when a runtime error occurred within the block.
Runtime errors occur while a program is running and cannot be detected by the PL/SQL compiler.
When a runtime error occurs, control is passed to the exception-handling section of the block. The
error is then evaluated, and a specific exception is raised and executed.
EXCEPTION
END;
DECLARE
v_first_name varchar2(35);
v_last_name varchar2(35);
BEGIN
FROM student
EXCEPTION
END;
SUBSTITUTION VARIABLES
SQL*PLUS allows a PL/SQL block to receive input information with the help of substitution
variables. Substitution variables cannot be used to output values, because no memory is allocated for
them.
DECLARE
v_first_name varchar2(35);
v_last_name varchar2(35);
BEGIN
FROM student
EXCEPTION
END;
CONDITIONAL STATEMENT
IF CONDITON 1 THEN
STATEMENT 1;
STATEMENT 2;
STATEMENT 3;
ELSE
STATEMENT N;
END IF;
For Example
DECLARE
BEGIN
ELSE
END IF;
END;
CASE STATEMENT
CASE SELECTOR
END CASE;
TASK 1
set feedback on
Name varchar2(30),
Salary number(15)
);
TASK 2
1 row created.
1 row created.
1 row created.
1 row created.
TASK 3
DECLARE
v_name varchar2(30);
v_salary number(15);
BEGIN
SELECT Salary
INTO v_salary
FROM Employee1
WHERE Name='John';
EXCEPTION
END;
TASK 4
DECLARE
v_salary number(15);
BEGIN
SELECT Salary
INTO v_salary
FROM Employee1
WHERE Name=v_name;
EXCEPTION
END;
TASK 5
DECLARE
v_salary number(15);
BEGIN
SELECT Salary
INTO v_salary
FROM Employee1
WHERE Name=v_name;
ELSE
END IF;
END;