BC remote Oracle DBA - Call (800) 766-1884
Free Oracle Tips

Oracle Consulting Oracle Training Development

Remote DBA

 

Remote DBA Plans
Remote DBA Service

 
Remote DBA Oracle Home
Remote DBA Oracle Training
Remote DBA SQL Tuning Consulting
Remote DBA Oracle Tuning Consulting
Remote DBA Data Warehouse Consulting
Remote DBA Oracle Project Management
Remote DBA Oracle Security Assessment
Remote DBA Unix Consulting
Burleson Books
Burleson Articles
Burleson Web Courses
Burleson Qualifications
Oracle Internals Magazine
Oracle Links
Remote DBA Oracle Monitoring
Remote DBA Support Benefits
Remote DBA Plans & Prices
Our Automation Strategy
What We Monitor
Oracle Apps Support
Print Our Brochure
Contact Us (e-mail)
Oracle Job Opportunities
Oracle Consulting Prices





   

 

 

   
  Oracle Tips by Burleson

Calling PL/SQL Functions from SQL*Plus

To call a function in SQL*Plus, simply embed it in a SQL statement.  Below we execute the f2c function by selecting it from the pseudo table called dual.  The “Dual” pseudo-table allows you to select from it to execute functions.

SQL> select f2c(40) from dual; 

   F2C(40)
----------
4.44444444 

The function can be applied to any select statement that passed the correct datatype.

SQL> select f2c(quantity) from sales; 

F2C(QUANTITY)
-------------
   537.777778
   -12.222222
   93.3333333
   204.444444
   426.666667
   82.2222222
   482.222222

   37.7777778
   4426.66667
   3037.77778
   4926.66667
   4871.11111
   37.7777778 

100 rows selected.

The above example calculates the degrees Celsius from all the quantity values in the sales table (pretending that they are actually degrees Fahrenheit).   For each row, the f2c function was executed, passing in the value of quantity for that row and returning that value converted to degrees Celsius. 

Below is an example of a function that takes an author’s first and last name and returns a formatted complete name.  Notice that it used the %type definition for the passed in the variables. 

SQL> create or replace function full_name
  2    (v_fname IN author.author_first_name%type,
  3     v_lname IN author.author_last_name%type)
  4    return varchar2
  5  as
  6  begin
  7    return initcap(v_fname||' '||v_lname);
  8  end;
  9  /
 

Function created.

SQL> select
  2    full_name(author_first_name, author_last_name) from author; 

FULL_NAME(AUTHOR_FIRST_NAME,AUTHOR_LAST_NAME)
----------------------------------------------------
Mark Jones
Alvis Hester
Erin Weaton
Pierre Jeckle
Lester Withers
Juan Petty
Louis Clark
Minnie Mee
Dirk Shagger
Diego Smith


The above book excerpt is from:

Easy Oracle PL/SQL Programming

Get Started Fast with Working PL/SQL Code Examples

ISBN 0-9759135-7-3   

John Garmany 

http://www.rampant-books.com/book_2005_1_easy_plsql.htm

Remote DBA Service
 

Oracle Tuning Book

Free Oracle dictionary reference poster

BC Oracle support

Oracle books by Rampant

Oracle monitoring software

North Carolina Oracle Users Group

 

 Arabian horse breeder

Seeing eye horses

 

 

Burleson is the American Team

American Flag

 

 

BC Remote Oracle Support
P.O. Box 511 • Kittrell, NC, 27544

Remote DBA

Remote DBA Services

 

Copyright © 1996 -  2011 by Burleson Enterprises. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation.