Term | Explanation |
---|---|
PL/SQL | Procedural Language extension of SQL used in Oracle databases. It adds procedural features like variables, loops, and conditions to SQL. |
Block | The basic unit of a PL/SQL program. Every PL/SQL code is written in blocks (anonymous or named). |
DECLARE | Section to declare variables, constants, cursors, and exceptions (optional). |
BEGIN | Mandatory section where the actual executable code (SQL & PL/SQL statements) is written. |
EXCEPTION | Optional section to handle runtime errors (exceptions). |
END | Marks the end of the PL/SQL block. |
Variable | A placeholder to store data temporarily during program execution. |
Constant | A variable whose value cannot be changed once initialized. |
Cursor | Used to retrieve multiple rows from a SELECT query, row-by-row. |
Loop | Allows repeated execution of a block of code. |
IF-THEN-ELSE | Conditional statement to perform different actions based on conditions. |
Procedure | A named PL/SQL block that performs a task. |
Function | Similar to a procedure, but it returns a value. |
Trigger | A PL/SQL block that executes automatically in response to an event (e.g., insert, update). |
Exception | Error condition during execution (e.g., NO_DATA_FOUND, TOO_MANY_ROWS). |
Basic syntax:
DECLARE
-- Variable declarations
variable_name datatype;
BEGIN
-- Executable statements
-- SQL and PL/SQL code goes here
DBMS_OUTPUT.PUT_LINE('Hello PL/SQL!');
EXCEPTION
-- Exception handling
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred.');
END;
/
Top comments (0)