Hi,
I have joined a new place and I am a bit surprised to see almost every SQL statement is inside a FOR LOOP cursor. The best example would be a sequence fetch. This too is inside a FOR LOOP. I have provided the code below.
Can someone pls explain whether there is any reason to do so ? Can't we fetch the same using a simple select statement "SELECT DAILY_SUMMARY.nextval INTO nNextSummaryId FROM DUAL" ? What will be the performance impact ?
FUNCTION GetNextSummaryId RETURN NUMBER IS
nNextSummaryId Number(15);
CURSOR Cur_Next_Sum_Id IS
SELECT DAILY_SUMMARY.nextval next_val
FROM DUAL;
BEGIN
FOR tmp_cur In Cur_Next_Sum_Id LOOP
nNextSummaryId := tmp_cur.next_val;
EXIT ;
END LOOP ;
RETURN(nNextSummaryId) ;
EXCEPTION
WHEN OTHERS THEN
RETURN(NULL) ;
END;