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

 

1.  DECLARE

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)

7.  RETURN NUMBER

8.  IS

9.  BEGIN

10. op_vc_var2:=upper(ip_vc_var1);

11. RETURN LENGTH(ip_vc_var1);

12. END;

13. BEGIN

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. /

 

Result:

The Length of the input is 12

The input in upper case is HELLO WORLD!

Script Explanation

Line no.

Description

1

Start of the declare section of the block.

2

The variable l_n_var1 of number data type is declared.

3

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

4

Start of the declaration of the function func_conv.

5

The input parameter ip_vc_var1 of varchar2 data type is declared.

6

The output parameter op_vc_var2 of varchar2 data type is declared.

7

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

8

Start of the declare section of the function.

9

Start of the execution section of the function.

10

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

11

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

12

End of the execution section of the function

13

Start of the execution section of the block.

14

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.

15

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

16

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

17,18

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