Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: Anonymous blocks: Sample Code Jump to:  
Category: >> Oracle PL/SQL >> Anonymous blocks: Sample Code Bookmark and Share

<< lastnext >>

Snippet Name: Anonymous blocks: Sample Code

Description: Anonymous blocks are run by copying them to the SQL*Plus command prompt then hitting the key

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 14th, 2009

--Simplest Anonymous Block      
 
BEGIN
  <valid statement>;
END;
/
BEGIN
  NULL;
END;
/
 
 
--Anonymous Block With Error Exception Handler      
 
BEGIN
  <valid statement>;
EXCEPTION
  <exception handler>;
END;
/
BEGIN
  NULL;
EXCEPTION
  WHEN OTHERS THEN
    NULL;
END;
/
 
 
--Nested Anonymous Blocks With Exception Handlers       
 
BEGIN
  <valid statement>;
  BEGIN
    <valid statement>;
  EXCEPTION
    <exception handler>;
  END;
EXCEPTION
  <exception handler>;
END;
/
BEGIN
  NULL;
  BEGIN
    NULL;
  EXCEPTION
    WHEN OTHERS THEN
     NULL;
  END;
  NULL;
EXCEPTION
  WHEN OTHERS THEN
    NULL;
END;
/
 
--
Nested Anonymous Blocks WITH Variable 
-- Declaration And Exception Handler 
 
DECLARE
 <variable name> <data type><(LENGTH precision)>;
BEGIN
  <valid statement>;
  BEGIN
    <valid statement>;
  EXCEPTION
    <exception handler>;
  END;
EXCEPTION
  <exception handler>;
END;
/
SET serveroutput ON
 
DECLARE
 x NUMBER(4);
BEGIN
  x := 1000;
  BEGIN
    x := x + 100;
  EXCEPTION
    WHEN OTHERS THEN
      x := x + 2;
  END;
  x := x + 10;
  DBMS_OUTPUT.put_line(x);
EXCEPTION
  WHEN OTHERS THEN
    x := x + 3;
END;
/
 
 
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 169 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?