Click here to Skip to main content
15,898,035 members
Articles / Programming Languages / SQL
Alternative
Tip/Trick

Combining Insert/Update to one Procedure

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
4 Apr 2011CPOL 4.5K   3  
For Oracle: -------------------------------------------------------------------------------- -- DESCRIPTION -- Universal save -- PARAMETERS IN -- vTRYB: mode: (I)nsert/(D)elete/(U)pdate -- rc: record -- PROCEDURE zapiszObiekt(vTRYB IN...
For Oracle:

--------------------------------------------------------------------------------
-- DESCRIPTION
--     Universal save
-- PARAMETERS IN
--     vTRYB:        mode: (I)nsert/(D)elete/(U)pdate
--     rc:           record
--
PROCEDURE zapiszObiekt(vTRYB IN VARCHAR2, rc IN ad_atr_obiektow%ROWTYPE) IS
BEGIN
  CASE
    WHEN vTRYB = 'D' THEN
      DELETE FROM ad_atr_obiektow WHERE kod = rc.kod;
    WHEN vTRYB = 'U' THEN
      UPDATE ad_atr_obiektow SET ROW = rc WHERE kod = rc.kod;
    ELSE
      INSERT INTO ad_atr_obiektow VALUES rc;
  END CASE;
END zapiszObiekt;


Sometimes, we can guess what mode is used or get it from application (DataRow.RowState for instance).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Poland Poland
Complicated

Comments and Discussions

 
-- There are no messages in this forum --