Home arrow Oracle arrow Database Interaction with PL/SQL, RECORD and TABLE in Sub-programs

Database Interaction with PL/SQL, RECORD and TABLE in Sub-programs

This is part 14 of a series of articles focusing on database interactions with Oracle PL/SQL. In my previous article, we concentrated on some tips for using procedures together with the introduction to functions. In this article we will look through several examples that cover using sub-programs in a very effective manner. I suggest you to go through part two in order to follow this article properly.

TABLE OF CONTENTS:
  1. Database Interaction with PL/SQL, RECORD and TABLE in Sub-programs
  2. Mixing PROCEDURE and FUNCTION
  3. Using RECORD with sub-programs
  4. Returning a RECORD from FUNCTION
  5. Working with PL/SQL TABLE and sub-programs
By: Jagadish Chatarji
Rating: starstarstarstarstar / 18
August 23, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Please note that all the examples in this series have been tested only with Oracle 10g. I didn’t really test them with all the previous versions of Oracle. I suggest you to refer the documentation of respective version you are using, if any of the programs failed to execute.

More about FUNCTION

My previous article actually stopped at a simple example on FUNCTION. Now we shall extend its limit. Consider the following example:

declare

CURSOR c_emp is

select ename,deptno from emp;

function getDname(p_deptno dept.deptno%type) return varchar2 is

v_dname dept.dname%type;

begin

select dname into v_dname

from dept where deptno = p_deptno;

 

return v_dname;

end;

begin

for r_emp in c_emp

loop

dbms_output.put_line(r_emp.ename || ',' || getDname(r_emp.deptno));

end loop;

end;

The above program really makes use of FUNCTION properly. We are sending ‘deptno’ as a parameter to the function ‘getDname’ which returns the department name back to the main program. Actually we can store the value returned back by ‘getDname’ (demonstrated in part 13), but it would be easy to write directly within the DBMS_OUTPUT statement in the main program as above.



 
 
>>> More Oracle Articles          >>> More By Jagadish Chatarji
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

ORACLE ARTICLES

- Oracle Java Security Woes Continue
- Oracle's New IaaS Cloud Option: There's a Ca...
- Oracle Acquires Eloqua to Boost Cloud Presen...
- Choosing Innovation: Oracle Survey Insights
- Oracle Fixes Privilege Escalation Bug
- Oracle`s Communications Service Availability...
- Oracle Releases Exalytics, Taleo Plans
- Oracle Releases Communications Network Integ...
- Oracle Releases Communications Data Model 11...
- Oracle Releases PeopleSoft PeopleTools 8.52
- Oracle Integrates Cloudera Apache Distro, My...
- Oracle Releases MySQL 5.5.18
- Oracle Announces NoSQL Database Availability
- Sorting Database Columns With the SELECT Sta...
- Retrieving Table Data with the LIKE Operator

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: