Summary of "PL/SQL tutorial 1: PL/SQL Block Types in Oracle Database By Manish Sharma"

Summary: PL/SQL tutorial (Blocks) — Manish (RebellionRider)

Overview

Block types

Structure of a PL/SQL block

Every PL/SQL block can contain up to three sections:

  1. Declaration section (optional)
    • Starts with the keyword DECLARE.
    • Used to define local identifiers: variables, constants, cursors, types, etc.
  2. Execution section (mandatory)
    • Starts with BEGIN and ends with END.
    • Contains executable statements, procedural logic, DML, and SQL*Plus built-ins.
    • To execute DDL at runtime, use Native Dynamic SQL (EXECUTE IMMEDIATE) or the DBMS_SQL package.
  3. Exception-handling section (optional)
    • Begins with EXCEPTION.
    • Contains handlers that run when runtime errors occur (specific handlers and/or WHEN OTHERS).

Anonymous block prototype

DECLARE
  -- declaration statements (optional)
BEGIN
  -- executable statements (mandatory)
EXCEPTION
  -- exception-handling statements (optional)
END;

Practical checklist when writing a PL/SQL block

  1. Decide block type: anonymous (quick, unnamed) or named (reusable).
  2. If you need local variables or cursors, add a DECLARE section and define identifiers.
  3. Always include an execution section (BEGIN ... END) and place procedural logic, SQL statements, and DML there.
  4. If runtime error handling is required, add an EXCEPTION section with specific handlers and/or WHEN OTHERS.
  5. To execute DDL at runtime, use EXECUTE IMMEDIATE (Native Dynamic SQL) or the DBMS_SQL package.
  6. End the block with END; (and add a trailing slash / when running in SQL*Plus if needed).

Additional notes

Speaker / Source

Category ?

Educational


Share this summary


Is the summary off?

If you think the summary is inaccurate, you can reprocess it with the latest model.

Video