Anonymous Block

An anonymous block applies to a script infrequently executed or a one-off activity. An anonymous block is executed in a session and is not stored.

Syntax

Figure 1 shows the syntax diagrams for an anonymous block.

Figure 1 anonymous_block::=

Details about the syntax diagram are as follows:

Examples

The following lists basic anonymous block programs:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
-- Null statement block:
BEGIN
     NULL; 
END;
/

-- Print information to the console:
BEGIN
     dbms_output.put_line('hello world!'); 
END; 
/

-- Print variable contents to the console:
DECLARE      
     my_var VARCHAR2(30);  
BEGIN      
     my_var :='world';     
     dbms_output.put_line('hello'||my_var); 
END; 
/