If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Update Store Procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-10-12, 07:51
stahorse1 stahorse1 is offline
Registered User
 
Join Date: Nov 2011
Posts: 13
Update Store Procedure

Hi

The current update store procedure that I have updates a list of input provided, but it there are fields that are left blank, they are being updated as null in the database.
I'm having a trouble creating a store procedure that will just update the provided fields only.

Please Help
Thanks
Reply With Quote
  #2 (permalink)  
Old 01-10-12, 08:40
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
If the procedure doesn't work what you want, it is probably because you wrote it incorrectly. As you didn't provide code, tables, data, etc., it is difficult to guess what might be wrong. A blind guess: WHERE clause is a culprit.
Reply With Quote
  #3 (permalink)  
Old 01-10-12, 08:44
flyboy flyboy is offline
Registered User
 
Join Date: Mar 2007
Posts: 546
Quote:
Originally Posted by stahorse1 View Post
I'm having a trouble creating a store procedure that will just update the provided fields only.
Have you considered using proper WHERE clause to UPDATE only rows with "the provided fields only"?
Reply With Quote
  #4 (permalink)  
Old 01-10-12, 09:50
stahorse1 stahorse1 is offline
Registered User
 
Join Date: Nov 2011
Posts: 13
I have lot of fields, that might be updated on the run time. Now I'm struggling with a query for that, run time update.

My current update would look like this:

create or replace PROCEDURE SP_UPD_EXCEPTION_LOG
(
p_ExceptionID IN INTEGER,
p_DateTimeStamp IN DATE,
p_Code IN VARCHAR2,
p_Description IN VARCHAR2,
p_Information IN VARCHAR2,
p_ApplicationID IN INTEGER,
p_rowID OUT NUMBER
)

AS

BEGIN
UPDATE "ExceptionsLog"
SET
"DateTimeStamp" = SYSDATE,
"Code" = p_Code,
"Description" = p_Description,
"Information" = p_Information,
"ApplicationID" = p_ApplicationID

WHERE "ExceptionID" = p_ExceptionID;

END SP_UPD_EXCEPTION_LOG;


but now if a user might update only two fields from that code, others are updated as null.
Reply With Quote
  #5 (permalink)  
Old 01-10-12, 10:02
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
>but now if a user might update only two fields from that code, others are updated as null.

so you need to modify the procedure to do as you desire.
try using IF ... THEN
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #6 (permalink)  
Old 01-10-12, 11:35
beilstwh beilstwh is offline
Lead Application Develope
 
Join Date: Jun 2004
Location: Liverpool, NY USA
Posts: 2,222
Code:
create or replace PROCEDURE SP_UPD_EXCEPTION_LOG
(
  p_ExceptionID IN INTEGER,
  p_DateTimeStamp IN DATE,
  p_Code IN VARCHAR2,
  p_Description IN VARCHAR2,
  p_Information IN VARCHAR2,
  p_ApplicationID IN INTEGER,
  p_rowID OUT NUMBER
)

AS

BEGIN
  UPDATE "ExceptionsLog"
  SET    
    "DateTimeStamp" = SYSDATE,
    "Code" = nvl(p_Code,"Code"),
    "Description" = nvl(p_Description,"Description"),
    "Information" = nvl(p_Information,"Information"),
    "ApplicationID" = nvl(p_ApplicationID,"ApplicationID")

  WHERE "ExceptionID" = p_ExceptionID;
  
END SP_UPD_EXCEPTION_LOG;
__________________
Bill
You do not need a parachute to skydive. You only need a parachute to skydive twice.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On