Re: open/fetch/loop in hiring questions

Re: open/fetch/loop in hiring questions

 

  

Here's my answer.

Open cursor,
loop
fetch into variable
if %NOTFOUND (immediately after the fetch) then exit

blah, blah, blah

end loop;

----------------------------------------------------

Here's a real example out of some code I'm working on:

open c_rooms for v_sql;

<<table_fill_loop>>
LOOP

FETCH c_rooms INTO rec_rooms;

EXIT WHEN c_rooms%NOTFOUND;

htp.tableRowOpen;

htp.p('<TD NOWRAP ALIGN="center" VALIGN="middle"><FONT SIZE="'||v_cell_size||'">'||rec_rooms.name||'</FONT></TD>');

v_times_index := times_table.FIRST;

WHILE times_table.EXISTS(v_times_index)
LOOP

v_cell_meeting_id := generic_structure.check_date(to_date(start_date||' '||times_table(v_times_index),'MON DD, YYYY HH:MI AM'),rec_rooms.room_id);


IF v_cell_meeting_id = 0 THEN
v_cell_string := vtc_rooms_available.room_links(v_cell_meeting_id,rec_rooms.room_id,num_people,start_date,times_table(v_times_index));
ELSE
v_cell_string := vtc_rooms_available.room_links(v_cell_meeting_id);

END IF;

htp.p('<TD NOWRAP ALIGN="center" VALIGN="middle">'||v_cell_string||'</TD>');

v_times_index := times_table.NEXT (v_times_index);

END LOOP;


htp.p('<TD NOWRAP ALIGN="center" VALIGN="middle"><FONT SIZE="'||v_cell_size||'">'||rec_rooms.name||'</FONT></TD>');

htp.tableRowClose;


END LOOP table_fill_loop;


Hope this isn't too long, but, should give you the idea in a whole block.

Kelly

----------------------------------------------------

On Thu, May 30, 2002 at 04:59:30PM -0700, after pounding the keys randomly, Laurie Gennari came up with....
> Hey gang-
>
> The recent flurry of me toos on the hiring questions inspired me to go through them. Does anyone have an example I can play with to see the answer to #7 in action? My brain just isn't wrapping around it today. In case you don't have a copy, question #7 is:
>
> In what order should a open/fetch/loop set of commands in a PL/SQL block be implemented if you use the %NOTFOUND cursor variable in the exit when statement? Why?
>
> Thanx,
>
> ltg
>
Oracle LazyDBA home page