Select the first names for the Doe family from the Worker table. : 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. 7. Select the first names for the Doe family from the Worker table.
SQL>
SQL>
SQL> create table employee (
  2  id                             number,
  3  employee_type_id               number,
  4  external_id                    varchar2(30),
  5  first_name                     varchar2(30),
  6  middle_name                    varchar2(30),
  7  last_name                      varchar2(30),
  8  name                           varchar2(100),
  9  birth_date                     date  ,
 10  gender_id                      number );

Table created.

SQL>
SQL>
SQL>
SQL>
SQL> set serveroutput on size 1000000;
SQL>
SQL> declare
  2
  3  v_first_name                          employee.first_name%TYPE;
  4  n_id                                  employee.id%TYPE;
  5
  6  FUNCTION get_first_name(
  7  aion_id                        in out employee.id%TYPE,
  8  aiv_last_name                  in     employee.last_name%TYPE)
  9  return                                employee.first_name%TYPE is
 10
 11  v_first_name                          employee.first_name%TYPE;
 12
 13  begin
 14    select id,first_name
 15    into   aion_id,v_first_name
 16    from   employee
 17    where  id > aion_id
 18    and    last_name like aiv_last_name||'%'
 19    and    rownum = 1;
 20
 21    return v_first_name;
 22  exception
 23    when NO_DATA_FOUND then
 24      return v_first_name;
 25    when OTHERS then
 26      raise_application_error(-20001, SQLERRM||' oselect employee'||' in show_worker');
 27  end get_first_name;
 28
 29  begin
 30    n_id := 0;
 31    loop
 32      v_first_name := get_first_name(n_id, 'DOE');
 33      if v_first_name is NULL then
 34        exit;
 35      end if;
 36      DBMS_OUTPUT.PUT_LINE(v_first_name);
 37    end loop;
 38  end;
 39  /

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL>
SQL> drop table employee;

Table dropped.
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.