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

 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
 Oracle Support

 SQL Tuning

 Oracle UNIX
 Oracle Linux
 Remote s
 Remote plans
 Application Server

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

 Remote S


 Consulting Staff
 Consulting Prices
 Help Wanted!


 Oracle Posters
 Oracle Books

 Oracle Scripts

Don Burleson Blog 







PL/SQL declare function within an anonymous block

Oracle PL/SQL tips by Boobal Ganesan

This is an excerpt from the book PL/SQL: The Definitive Reference by Boobal Ganesan.

The below approach explains how a function can be declared in an anonymous block without creating them permanently in the database. The declaration of the function should be always at the end of the declare section of an anonymous block after all the necessary declarations of the anonymous block are declared.


These functions cannot be viewed in the data dictionary tables as these are not permanently saved in the database.



2.  l_n_var1  NUMBER;

3.  l_vc_var2 VARCHAR2(30);

4.  FUNCTION func_conv(

5.  ip_vc_var1 IN VARCHAR2,

6.  op_vc_var2 OUT VARCHAR2)


8.  IS


10. op_vc_var2:=upper(ip_vc_var1);

11. RETURN LENGTH(ip_vc_var1);

12. END;


14. l_n_var1:=func_conv('Hello World!',l_vc_var2);

15. dbms_output.put_line('The Length of the input is '||l_n_var1);

16. dbms_output.put_line('The input in upper case is '||l_vc_var2);

17. END;

18. /



The Length of the input is 12

The input in upper case is HELLO WORLD!

Script Explanation

Line no.



Start of the declare section of the block.


The variable l_n_var1 of number data type is declared.


The variable l_vc_var2 of varchar2 data type with precision 30 is declared.


Start of the declaration of the function func_conv.


The input parameter ip_vc_var1 of varchar2 data type is declared.


The output parameter op_vc_var2 of varchar2 data type is declared.


The return statement's data type is declared as number..


Start of the declare section of the function.


Start of the execution section of the function.


The case of the input parameter ip_vc_var1 is converted to upper and assigned to the output parameter op_vc_var2.


The length of the input parameter ip_vc_var1 is calculated and returned using the RETURN statement.


End of the execution section of the function


Start of the execution section of the block.


The function func_conv is called with the text 'Hello World!' as its input parameter and the local variable l_vc_var2 is used as its output variable and the function is assigned to another local variable l_n_var1.


The local variable l_n_var1's value is printed using the DBMS_OUTPUT.PUT_LINE procedure.


The local variable l_vc_var2's value is printed using the DBMS_OUTPUT.PUT_LINE procedure.


End of the execution section of the block.


Oracle Training from Don Burleson 

The best on site "Oracle training classes" are just a phone call away! You can get personalized Oracle training by Donald Burleson, right at your shop!

Oracle training



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