Wednesday, May 1, 2013

Anonymous Blocks


Anonymous Blocks:

Anonymous blocks of code are not stored, and not named. They are executed insession
and cannot be called from another session. To execute the same code again,
you must save the anonymous block to an OS file and run it, type it in again, or
include it in a program that executes the block when needed.
You will find throughout the examples that anonymous blocks are used extensively.
Anonymous blocks are perfect for scripting, or activities that you do not wish to
repeat frequently. The following example is an anonymous block:

SET SERVEROUTPUT ON
DECLARE
v_Date TIMESTAMP;
BEGIN
SELECT systimestamp - 1/24
INTO v_Date
FROM dual;
DBMS_OUTPUT.PUT_LINE('One hour ago: '||v_Date);
END;
/


The block begins with DECLARE or BEGIN and is not stored anywhere once
Executed.

No comments:

Post a Comment