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 > Data Access, Manipulation & Batch Languages > ANSI SQL > Procedure doesn't work ...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-03-03, 08:13
Lazy Lazy is offline
Registered User
 
Join Date: Sep 2003
Location: Brussel
Posts: 52
Arrow Procedure doesn't work ...

I have this procedure running in my database (Oracle 8i) to update the enddate of a task. When a task has overdue I give the enddate the values of the sysdate.

Everything worked when I created it 15 october and worked until 31 october. That was the last DDL. Since then when tasks have overdue this procedure (who is called in a ColdFusion page) hasn't updated overdued enddates.

Here is my source:

PROCEDURE PR_UPD_OLD IS
CURSOR c_getold IS
SELECT *
FROM task
WHERE to_char(enddate, 'dd-mm-yy') <= to_char(sysdate-1, 'dd-mm-yy');
BEGIN
FOR r_getold IN c_getold LOOP
UPDATE task
SET enddate = sysdate
WHERE taskid = r_getold.taskid;
END LOOP;

COMMIT;

EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
END;

Please help,
thanks!
__________________
A good programmer is a LAZY programmer!
Reply With Quote
  #2 (permalink)  
Old 11-03-03, 08:40
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Procedure doesn't work ...

What on Earth are those TO_CHARs for? They are a bug. Suppose end_date was 1st December 2003 and sysdate is 3rd November 2003, which is earlier.

using your TO_CHAR end_date becomes the string '01-12-2003' and sysdate-1 becomes the string '02-11-2003'. When you compare these 2 strings, guess which one is smallest? The one that begins with '01...'

The correct cursor would be:

CURSOR c_getold IS
SELECT *
FROM task
WHERE enddate <= sysdate-1

Actually, the whole procedure would be better without the cursor and exception section:

PROCEDURE PR_UPD_OLD IS
BEGIN
UPDATE task
SET enddate = sysdate
WHERE enddate <= sysdate-1;
COMMIT;
END;

Now if it fails for some reason you will see an error message.

Personally, I wouldn't commit within the procedure either, but that's just my preference. I think the user/application that calls your procedure should be in charge of the whole transaction.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
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