Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

IF condition inside the for FOR LOOP

$
0
0
Please clear my doubt on the below function

1. Where the control will go if the condition got failed after the For loop

2. What is the purpose of the Exit here


FUNCTION new_rental(
memberid IN rental.member_id%TYPE,
titleid IN rental.title_id%TYPE) RETURN DATE IS
CURSOR copy_csr IS
SELECT * FROM title_copy WHERE title_id = titleid FOR UPDATE;
flag BOOLEAN := FALSE;
BEGIN
FOR copy_rec IN copy_csr LOOP
IF copy_rec.status = 'AVAILABLE' THEN
UPDATE title_copy
SET status = 'RENTED' WHERE CURRENT OF copy_csr;
INSERT INTO rental(book_date, copy_id, member_id,
title_id, exp_ret_date)
VALUES (SYSDATE, copy_rec.copy_id, memberid,
titleid, SYSDATE + 3);
flag := TRUE;
EXIT;
END IF;
END LOOP;
COMMIT;
IF flag THEN
RETURN (SYSDATE + 3);
ELSE
reserve_movie(memberid, titleid);
RETURN NULL;
END IF;
EXCEPTION
WHEN OTHERS THEN
exception_handler(SQLCODE, 'NEW_RENTAL');
END new_rental;





Thanks,
Ganesh

Viewing all articles
Browse latest Browse all 13329

Trending Articles