SunQuest
 
       Oracle
  Home arrow Oracle arrow Page 2 - Database Interaction with PL/SQL, Name...
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, Named Notations, Storing Procedures and Functions
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 21
    2005-09-06

    Table of Contents:
  • Database Interaction with PL/SQL, Named Notations, Storing Procedures and Functions
  • What are Parameter Default values?
  • What are STORED PROCEDURES?
  • What are STORED FUNCTIONS?
  • PACKAGE and PACKAGE BODY

  • 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
     
    IBM developerWorks
     
    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, Named Notations, Storing Procedures and Functions - What are Parameter Default values?


    (Page 2 of 5 )

    This is almost similar to the DEFAULT clause you use with column definition. If you don’t provide any value to the column, the DEFAULT value is chosen to replace null automatically. In the same manner, we can design our parameters to the sub-programs in a very flexible manner. We can provide DEFAULT values to the parameters. That means the parameter values are not compulsory. But if we send parameter values, parameters get bound to those values. Let us consider the following program.

    declare
     procedure dispEmp(p_sal emp.sal%type := 0, p_deptno emp.deptno%type := null) is
     begin
      if p_deptno is null then
       for r_emp in (select ename from emp where sal > p_sal)
       loop
        dbms_output.put_line(r_emp.ename);
       end loop;
      else
       for r_emp in (select ename from emp where sal > p_sal and deptno = p_deptno)
       loop 
        dbms_output.put_line(r_emp.ename);
       end loop;
      end if;
     end;
    BEGIN
     dispEmp(1000,10);
        dbms_output.put_line('-------------');
     dispEmp(2000);
        dbms_output.put_line('-------------');
     dispEmp(p_deptno => 20);
    END;

    Even though the above program is bit lengthy, it is actually very easy to understand.  If you observe the declaration of procedure, it is something like the following:

    procedure dispEmp(p_sal emp.sal%type := 0, p_deptno emp.deptno%type := null) is

    The above declaration says that ‘p_sal’ should be considered 0 when no value is provided. Similarly ‘p_deptno’ should be considered null when no value is provided for it.

    dispEmp(1000,10);

    The above statement states that ‘p_sal’ should be treated as 1000 and ‘p_deptno’ should be treated as 10.

    dispEmp(2000);

    The above statement states that ‘p_sal’ should be treated as 2000 and ‘p_deptno’ should be treated as null.

    dispEmp(p_deptno => 20);

    The above statement states that ‘p_sal’ should be treated as 0 and ‘p_deptno’ should be treated as 20. If you observe the above statement carefully, without the named notation, it is impossible to send the value only to ‘p_deptno’.

    More Oracle Articles
    More By Jagadish Chatarji


       · Hello guys, this is my article on working with stored procedures and functions in...
     

       

    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

    IBM developerWorks




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