Using PL/SQL ANONYMOUS block statements
The ANONYMOUS
blocks are standard PL/SQL blocks that provide the ability to build and execute the procedures at runtime, without storing the information in the system catalog. Anonymous blocks do not carry names, and so, can't be referenced by other database objects.
The ANONYMOUS
block can contain three sections, which are the declaration section, the execution section, and the exceptional handling section. We can execute these ANONYMOUS
blocks from DB2 CLP, DB2 APIs, and various tools, such as Optim database administrator, CLPPlus, and so on.
Getting ready
Interestingly, we do not require any privilege to invoke an anonymous block, but necessary privileges should be available in the base table to invoke the SQL statements.
How to do it...
1. Let's start writing a simple
ANONYMOUS
block statement. Remember thatANONYMOUS
blocks will have no names associated with it.SET SERVEROUTPUT ON; BEGIN NULL;-- END;
This
ANONYMOUS
block will not return anything...