PL/SQL Anonymous block

An PL/SQL anonymous block consists of a sequence of instructions, the block will be executed only once.
The PL/SQL anonymous block is not normally stored in the database for reuse later.

Syntax

DECLARE -- Declarative part (optional)
-- Declarations of local types, variables, subprograms
BEGIN -- Executable part (required)
-- SQL statements
-- PL/SQL statements
EXCEPTION -- Exception-handling part (optional)
-- Exception handlers for exceptions (errors) raised in executable part
END; -- End of executable part (required)

Example

DECLARE 
 v_variable VARCHAR2(50);
BEGIN 
 SELECT name
 INTO v_variable
 FROM students;
 dbms_output.put_line('Student name: '||v_variable);
EXCEPTION 
 WHEN no_data_found THEN
 dbms_output.put_line('No data found in the table students');
END;