Oracle
  Home arrow Oracle arrow Developing Simple PL/SQL Stored Proced...
Dev Shed Forums 
Administration  
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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

Developing Simple PL/SQL Stored Procedures for CRUD Operations
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 24
    2007-02-19

    Table of Contents:
  • Developing Simple PL/SQL Stored Procedures for CRUD Operations
  • Validate information before inserting a row using a PL/SQL stored procedure: code
  • Validate information before inserting a row using a PL/SQL stored procedure: explanation
  • How to update a row in a table using a PL/SQL stored procedure
  • Deleting and retrieving values using PL/SQL stored procedures

  • 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

    Virtual Tradeshows by Ziff Davis Enterprise - A Unique Opportunity to Connect with IT Experts, Access Information, and Gain Insight on today's Technology

    Developing Simple PL/SQL Stored Procedures for CRUD Operations
    (Page 1 of 5 )

    In this article, I shall go through a set of PL/SQL stored procedures which are very frequently used for CRUD operations. These stored procedures are mainly helpful for the developers who develop client applications (involving business logic or user interface design and programming) and who need a data layer to be implemented using PL/SQL stored procedures. The article is not targeted at pure PL/SQL developers.

    All the examples in this series have been tested only with Oracle 10g (V10.2).  I didn’t really test any of the examples in any of the previous versions.  If you have any problems during the execution of these examples, please post in the discussion area. 

    How to insert a row into a table using a PL/SQL stored procedure

    The following is the stored procedure which deals with inserting a particular row into a table.

    create or replace procedure p_emp_insert (p_empno emp.empno%type,
    p_ename emp.ename%type, p_sal emp.sal%type, p_deptno emp.deptno%
    type) as
    begin
          insert into emp
          (
                empno,
                ename,
                sal,
                deptno
          )
          values
          (
                p_empno,
                p_ename,
                p_sal,
                p_deptno    
          );
          Commit;
    exception
          when dup_val_on_index then
                raise_application_error(-20001, 'Employee already
    exists');
          when others then
                raise_application_error(-20011, sqlerrm);
    end;
    /

    The above is a stored procedure named “p_emp_insert” which accepts four parameters.  Once all the parameters are passed in, it executes an INSERT statement to insert (or add) those values in the form of a row.  The following is the code available in the error handling (or exception handling) section, which mainly deals with errors/exceptions raised at run-time:

          when dup_val_on_index then
                raise_application_error(-20001, 'Employee already
    exists');
          when others then
                raise_application_error(-20011, sqlerrm);

    I mainly worked with two of the pre-defined exceptions, namely “dup_val_on_index” and “others.”  The “dup_val_on_index” is mainly raised when the runtime tries to insert a row with a repeated value in a unique or primary column.  The “others” exception is raised when the runtime come across any other errors (apart from “dup_val_on_index,” as it is already handled).  The SQLERRM is a built-in item which mainly contains the error message for the error or exception raised.

    To execute the above stored procedure, you can issue the following command at the SQL prompt:

    SQL> EXEC p_emp_insert(1001, 'Jag', 3400, 30)

    More Oracle Articles
    More By Jagadish Chatarji


       · Hello guys. This is my contribution, exclusively for application developers. This...
       · Really this really very nice the way it is.some more add programs related to stored...
     

       

    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

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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