Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

PL/SQL function examples

Oracle PL/SQL Tips by Donald BurlesonMarch 18, 2015

Question:  I want some examples of the PL/SQL functions syntax.

Answer:  PL/SQL functions allow only INPUT parameters and they must return a value.

Here is a PL/SQL function example to change Fahrenheit temperatures to centigrade:

CREATE OR REPLACE FUNCTION
c_to_f (degree NUMBER) RETURN NUMBER IS
buffer NUMBER;
BEGIN
buffer := (degree * 9/5) + 32;
RETURN buffer;
END;
/
;

show errors

select c_to_f(45) from dual;


-- This is a PL/SQL function example to add tax based on a state tax list:

reate or replace function plus_tax_2(i_stor_id in varchar2, i_title_id in varchar2)
return number
as
v_total number;
v_msrp number;
v_state varchar2(2);
v_tax_pct number;
not_valid_state exception;
cursor c1 is
select
price,
state
from
titles ti,
sales sa,
stores st
where
st.stor_id = sa.stor_id
and
sa.title_id = ti.title_id
and
st.stor_id = i_stor_id
and
ti.title_id = i_title_id;
begin
open c1;
fetch c1 into v_msrp, v_state;

IF v_state = 'CA' then
v_tax_pct := .08;
ELSIF v_state = 'WA' THEN
v_tax_pct := .06;
ELSIF v_state = 'OR' THEN
v_tax_pct := .05;
ELSE
RAISE not_valid_state;
END IF;

v_total := v_msrp + (v_msrp * v_tax_pct);
return v_total;
close c1;
EXCEPTION
WHEN not_valid_state then
RAISE_APPLICATION_ERROR(-20020,
'This state is not valid: ' || v_state);

end;
/

show errors

select plus_tax_2('8042', 'BU1111') from dual;


 
Get the Complete
Oracle SQL Tuning Information 

The landmark book "Advanced Oracle SQL Tuning  The Definitive Reference"  is filled with valuable information on Oracle SQL Tuning. This book includes scripts and tools to hypercharge Oracle 11g performance and you can buy it for 30% off directly from the publisher.

 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster