Using stored functions in SQL statements, function getName : Create Procedure « Function Procedure Packages « 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 » Function Procedure Packages » Create Procedure 
27. 6. 7. Using stored functions in SQL statements, function getName
SQL>
SQL>
SQL> create table company(
  2     product_id        number(4)    not null,
  3     company_id          NUMBER(8)    not null,
  4     company_short_name  varchar2(30not null,
  5     company_long_name   varchar2(60)
  6  );

Table created.

SQL> insert into company values(1,1001,'A Inc.','Long Name A Inc.');

row created.

SQL> insert into company values(1,1002,'B Inc.','Long Name B Inc.');

row created.

SQL> insert into company values(1,1003,'C Inc.','Long Name C Inc.');

row created.

SQL> insert into company values(2,1004,'D Inc.','Long Name D Inc.');

row created.

SQL> insert into company values(2,1005,'E Inc.','Long Name E Inc.');

row created.

SQL> insert into company values(2,1006,'F Inc.','Long Name F Inc.');

row created.

SQL>
SQL>
SQL>
SQL> CREATE OR REPLACE FUNCTION getName
  2                 (ip_product_id NUMBER,
  3                  ip_company_id NUMBER)
  4  RETURN VARCHAR2
  5  IS
  6    v_name VARCHAR2(120);
  7  BEGIN
  8
  9    SELECT 'Org Name: (Short'||company_short_name||' (Long'||company_long_name
 10    INTO v_name
 11    FROM company
 12    WHERE product_id = ip_product_id
 13    AND company_id = ip_company_id;
 14
 15    RETURN (v_name);
 16  END getName;
 17  /

Function created.

SQL>
SQL> SELECT getName(product_id,company_id"Formatted Org Name"
  2  FROM company
  3  ORDER BY product_id,company_id;

Formatted Org Name
----------------------------------------------------------------------
Org Name: (ShortA Inc. (LongLong Name A Inc.
Org Name: (ShortB Inc. (LongLong Name B Inc.
Org Name: (ShortC Inc. (LongLong Name C Inc.
Org Name: (ShortD Inc. (LongLong Name D Inc.
Org Name: (ShortE Inc. (LongLong Name E Inc.
Org Name: (ShortF Inc. (LongLong Name F Inc.

rows selected.

SQL>
SQL> drop table company;

Table dropped.

SQL>
27. 6. Create Procedure
27. 6. 1. Creating a procedure
27. 6. 2. Creating a Stored Procedure for table update
27. 6. 3. Call a trigger in procedure
27. 6. 4. Re-creating a Procedure By Using OR REPLACE
27. 6. 5. Exceptions in Subprograms
27. 6. 6. Forward Declarations
27. 6. 7. Using stored functions in SQL statements, function getName
27. 6. 8. Create procedure for AUTHID CURRENT_USER
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.