Skip to main content
← PL/SQL Topics

Language Basics

Explain the PL/SQL block structure (DECLARE, BEGIN, EXCEPTION, END) and comment styles

Block Structure and Comments

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

Every PL/SQL program is a block with an optional declarative part, a mandatory executable part, and an optional exception part.

How it works

A PL/SQL block has three sections: DECLARE (optional — variables, cursors, types, subprograms), BEGIN ... (required — the executable statements), and EXCEPTION (optional — handlers), closed by END. An anonymous block has no name and is compiled and run each time; named blocks are procedures, functions, packages and triggers stored in the database. Comments are -- to end of line, or /* ... */ spanning multiple lines.

How it works
DECLARE
  -- single-line comment
  v_total NUMBER := 0;
BEGIN
  /* multi-line comment:
     sum a couple of values */
  v_total := 10 + 20;
  DBMS_OUTPUT.PUT_LINE('Total = ' || v_total);
EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Failed: ' || SQLERRM);
END;
/

Related questions

GroundingGenerated

Model-generated, grounded against the curated knowledge layer. Check specifics against your instance.

Have a follow-up, or a different question?

Continue in Ask Oracle AI