Oracle
  Home arrow Oracle arrow Page 3 - 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 
Actuate Whitepapers 
VeriSign Whitepapers 
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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Database Interaction with PL/SQL: Sub-programs in Depth - Procedures with parameters


    (Page 3 of 5 )

    Parameters (or arguments) are very common in almost any type of programming language. If you know SQL (obviously), you will see several SQL functions like SUM, MAX, TO_UPPER and so on. All of them accept parameters (or arguments). The values you send to those functions are nothing but the parameters.

    The value you send as a parameter to a function should match the data type it can accept. For example, the SUM function accepts only column as a parameter. More specificly, it accepts only a numeric column. So every parameter has to be defined with its own data type and width.

    Coming to our scenario, even a sub-program can be declared and defined with parameters as well. But, we need to care about the data type, width and other stuff. The declaration of a parameter will be very similar to that of a variable declaration. And these are nearly similar to ‘cursors with parameters’ discussed in part 11 of this series. Consider the following example:

    declare

                procedure dispEmp(p_deptno dept.deptno%type) as

                            cursor c_emp is

                                        select ename, sal from emp

                                        where deptno = p_deptno;

                begin

                            for r_emp in c_emp

                            loop

                                        dbms_output.put_line(r_emp.ename || ',' || r_emp.sal);  

                            end loop;

                end;

    BEGIN

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

                dbms_output.put_line('EMPLOYEES');

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

                dispEmp(10);

    END;

    For the sake of clarity, let us rewrite the above with only the important statements:

    declare

                procedure dispEmp(p_deptno dept.deptno%type) as

    .

    .

    .

                begin

                            .

                            .

                end;

    BEGIN

                .

    .

    .

                dispEmp(10);

    END;

    I hope I need not explain any more. A value ‘10’ is being passed from th  main program to the sub-program using the statement ‘dispEmp(10)’.  This value is caught in ‘p_deptno’ and finally used in the SELECT statement of the CURSOR declaration.

    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

    - 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
    - Focusing on Templates in Oracle HTML DB





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