Oracle
  Home arrow Oracle arrow Page 4 - Database Interaction with PL/SQL: Sub-...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ORACLE

Database Interaction with PL/SQL: Sub-programs in Depth
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2005-08-16

    Table of Contents:
  • Database Interaction with PL/SQL: Sub-programs in Depth
  • Sub-programs interacting with an Oracle database
  • Procedures with parameters
  • Using %ROWTYPE in parameter declarations
  • Introduction to FUNCTION

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Database Interaction with PL/SQL: Sub-programs in Depth - Using %ROWTYPE in parameter declarations


    (Page 4 of 5 )

    In the previous section, I used the parameter with a simple data type (or with %TYPE). We can also use parameters with %ROWTYPE.  Let us consider the following example:

    declare

                cursor c_emp is

                            select * from emp;

                procedure dispEmp(p_emp emp%rowtype) as

                begin

                            dbms_output.put_line('No : ' || p_emp.empno);

                            dbms_output.put_line('Name : ' || p_emp.ename);

                            dbms_output.put_line('Salary : ' || p_emp.sal);

                            dbms_output.put_line('Deptno : ' || p_emp.deptno);

                            dbms_output.put_line('-----------------------');

                end;

    BEGIN

                for r_emp in c_emp

                loop

                            dispEmp(r_emp);

                end loop;

    END;

    If you clearly observe the above program, I am using the procedure ‘dispEmp’ to display the information of an employee line by line. I am using CURSOR outside the procedure. That means the cursor is accessible to both the main program and procedure ‘dispEmp’ as well.  But my intention for ‘dispEmp’ is just to display the information of a given employee (actually passed through parameter).

    In our main program, for each iteration of the FOR loop, I am passing an entire row of an employee to the parameter ‘p_emp’ of the procedure ‘dispEmp’. The variable ‘p_emp’ is declared as of type ‘emp%rowtype’.  So, it can hold an entire row from the table ‘emp’ (which is the same as CURSOR).

    The output of the above program will be something like printing labels for all employees.

    More Oracle Articles
    More By Jagadish Chatarji


       · Hello guys, this is my in-depth article on working with sub-programs in PL/SQL. You...
     

       

    ORACLE ARTICLES

    - Implementing and Using Oracle`s Restore Poin...
    - Tuning PL/SQL Code
    - Debugging PL/SQL Code
    - Testing PL/SQL Code
    - Working With PL/SQL Code
    - Conditional Compilation for Oracle Database ...
    - Compile-Time Warnings for Oracle DB 10g
    - Compiling PL/SQL Code for an Oracle Database
    - Troubleshooting PL/SQL Code
    - Managing PL/SQL Code
    - Data Manipulation and More for HTML DB Appli...
    - Oracle Database Fundamentals
    - Adding Processes to HTML DB Applications
    - Adding Computations, Processes, and Validati...
    - Sub-templates and More with Oracle HTML DB





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway