Uses a PL/SQL Nested Block : Code Block « PL SQL Programming « Oracle PL/SQL Tutorial

Oracle PL/SQL Tutorial
1. Introduction
2. Query Select
3. Set
4. Insert Update Delete
5. Sequences
6. Table
7. Table Joins
8. View
9. Index
10. SQL Data Types
11. Character String Functions
12. Aggregate Functions
13. Date Timestamp Functions
14. Numerical Math Functions
15. Conversion Functions
16. Analytical Functions
17. Miscellaneous Functions
18. Regular Expressions Functions
19. Statistical Functions
20. Linear Regression Functions
21. PL SQL Data Types
22. PL SQL Statements
23. PL SQL Operators
24. PL SQL Programming
25. Cursor
26. Collections
27. Function Procedure Packages
28. Trigger
29. SQL PLUS Session Environment
30. System Tables Data Dictionary
31. System Packages
32. Object Oriented
33. XML
34. Large Objects
35. Transaction
36. User Privilege
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL/SQL Tutorial » PL SQL Programming » Code Block 
24. 4. 3. Uses a PL/SQL Nested Block
SQL>
SQL>
SQL> CREATE TABLE myItemTable (
  2     item_code varchar2(6PRIMARY KEY,
  3     item_descr varchar2(20NOT NULL);

Table created.

SQL>
SQL>
SQL>
SQL> DECLARE
  2    v_item_code VARCHAR2(6);
  3    v_item_descr VARCHAR2(20);
  4    v_num NUMBER(1);
  5  BEGIN
  6
  7    v_item_code :='Java2s';
  8
  9    v_item_descr :='a website for Oracle';
 10
 11    BEGIN
 12
 13      SELECT INTO v_num FROM myItemTable WHERE item_code =v_item_code;
 14
 15    EXCEPTION
 16
 17      WHEN NO_DATA_FOUND THEN
 18        v_num :=0;
 19
 20      WHEN OTHERS THEN
 21        dbms_output.put_line('Error in SELECT:'||SQLERRM);
 22        RETURN;
 23    END;
 24
 25    IF (v_num =0)THEN
 26
 27      INSERT INTO myItemTable VALUES (v_item_code,v_item_descr);
 28
 29    END IF;
 30    dbms_output.put_line('Successful Completion');
 31  EXCEPTION WHEN OTHERS THEN
 32    dbms_output.put_line(SQLERRM);
 33  END;
 34  /
Successful Completion

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL> select from myItemTable;

ITEM_C ITEM_DESCR
------ --------------------
Java2s a website for Oracle

row selected.

SQL>
SQL> drop table myItemTable;

Table dropped.

SQL>
SQL>
24. 4. Code Block
24. 4. 1. This is an anonymous procedure, so it has no name
24. 4. 2. A PL/SQL Block
24. 4. 3. Uses a PL/SQL Nested Block
24. 4. 4. Inline procedure
24. 4. 5. the forward slash on a line by itself says execute this procedure
24. 4. 6. Inner function
24. 4. 7. Select the first names for the Doe family from the Worker table.
24. 4. 8. Inner procedure in an anonymous function
24. 4. 9. Demonstrate nested PL/SQL blocks
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.