It depends on what you need the result for.
If you are sure that there will be only one line, use the implicit cursor:
DECLARE v_foo foobar.foo%TYPE; v_bar foobar.bar%TYPE; BEGIN SELECT foo,bar FROM foobar INTO v_foo, v_bar;
If you want to select more than one row, you can use an explicit cursor:
DECLARE CURSOR cur_foobar IS SELECT foo, bar FROM foobar; v_foo foobar.foo%TYPE; v_bar foobar.bar%TYPE; BEGIN
or use another type of cursor:
BEGIN -- Open the cursor and loop through the records FOR v_rec IN (SELECT foo, bar FROM foobar) LOOP -- Print the foo and bar values dbms_output.put_line('foo=' || v_rec.foo || ', bar=' || v_rec.bar); END LOOP; END;
Sergey Stadnik Dec 09 '08 at 4:09 2008-12-09 04:09
source share