954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Cursor%FOUND problem

Hi,
I can't find the missing thing in this code. "05-MAY-08" is in the table but, ( CURSOR_TARIH%FOUND ) never returns TRUE. When i do manuel query it is ok.
Thanks

create or replace
PROCEDURE A_SIPARIS_EKLE_SP 
IS

CURSOR CURSOR_TARIH IS 
SELECT TARIH FROM A_ACCOUNT WHERE TARIH = to_date('05-MAY-08', 'DD-MM-YY');

BEGIN

OPEN CURSOR_TARIH;

INSERT INTO A_SIPARIS (MID,STATUS) VALUES (1, 'NO');

IF ( CURSOR_TARIH%FOUND ) THEN
  UPDATE A_ACCOUNT SET PRICE = '10' WHERE TARIH = to_date('05-MAY-08', 'DD-MM-YY');  
ELSE
  INSERT INTO A_ACCOUNT( TARIH, PRICE) values ( SYSDATE,  '1' );
END IF;

COMMIT;

CLOSE CURSOR_TARIH;

END;
veledrom
Master Poster
758 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

Can you please share your solution?

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

I don't insert date with SYSDATE anymore. I use VARCHAR for it and get date manual.

veledrom
Master Poster
758 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

> TO_DATE('05-MAY-08', 'DD-MM-YY')

Isn't it because of the mismatch between "MAY" and "MM"?
Try replacing "MM" with "MON".

A Hill
Newbie Poster
1 post since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

You must enter the date in the format that you specified in the script ('DD.MM.YY' or 'DD-MON-YY') and it looks like you forgot to do fetch

I added comments to the lines that I corrected / added.
I hope it will be helpful

CREATE OR REPLACE
PROCEDURE A_SIPARIS_EKLE_SP 
IS
 
CURSOR CURSOR_TARIH IS 
--SELECT TARIH FROM A_ACCOUNT WHERE TARIH = TO_DATE('05-MAY-08', 'DD-MM-YY');
SELECT TARIH FROM A_ACCOUNT WHERE TARIH = TO_DATE('05-MAY-08', 'DD-MON-YY'); -- correct

tarihValue date;  -- add
 
BEGIN
 
OPEN CURSOR_TARIH;
 
INSERT INTO A_SIPARIS (MID,STATUS) VALUES (1, 'NO');
 
FETCH CURSOR_TARIH INTO tarihValue;  -- add
IF ( CURSOR_TARIH%FOUND ) THEN
  --UPDATE A_ACCOUNT SET PRICE = '10' WHERE TARIH = TO_DATE('05-MAY-08', 'DD-MM-YY');  
  UPDATE A_ACCOUNT SET PRICE = '10' WHERE TARIH = TO_DATE('05-MAY-08', 'DD-MON-YY');  -- correct  
ELSE
  --INSERT INTO A_ACCOUNT( TARIH, PRICE) VALUES ( SYSDATE,  '1' );
  INSERT INTO A_ACCOUNT( TARIH, PRICE) VALUES ( TRUNC(SYSDATE),  '1' );  -- correct
END IF;
 
COMMIT;
 
CLOSE CURSOR_TARIH;
 
END;
babyDBA
Newbie Poster
10 posts since Sep 2009
Reputation Points: 10
Solved Threads: 5
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You