You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
PL/SQL (Procedural Language/SQL) is Oracle's powerful procedural extension to SQL. It combines the data manipulation power of SQL with the processing power of procedural languages, allowing you to write complex business logic that runs directly in the database.
Every PL/SQL program is built from blocks:
DECLARE
-- Variable declarations (optional)
v_name VARCHAR2(50);
v_salary NUMBER(10, 2);
BEGIN
-- Executable statements (required)
SELECT first_name, salary
INTO v_name, v_salary
FROM employees
WHERE employee_id = 100;
DBMS_OUTPUT.PUT_LINE(v_name || ' earns ' || v_salary);
EXCEPTION
-- Error handling (optional)
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Employee not found');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error: ' || SQLERRM);
END;
/
| Section | Purpose | Required? |
|---|---|---|
DECLARE | Declare variables, constants, cursors | Optional |
BEGIN...END | Executable code | Required |
EXCEPTION | Error handling | Optional |
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.