Re: jumping to records

From: Matt B. <mcb_at_fightspam.sd.znet.com>
Date: 2000/06/18
Message-ID: <skq0unjbe7f12_at_corp.supernews.com>#1/1


"A D Hager" <adhager_at_its.brooklyn.cuny.edu> wrote in message news:394C64AF.D184EAE2_at_its.brooklyn.cuny.edu...
>
> Is it possible to select all records from a table but to jump to a
> particular one?
> for example suppose I want to retrieve all records from a table but I
> want to start somewhere in the middle.
> If I execute
> select * from employees where name='aaron'
> I will only get one record.
> If I execute
> select * from employees;
> I will only get all the records and will have to retrieve many records
> before finding the one I am looking for.
>
> Thanks a lot,
>
> Aaron

You need PL/SQL for that:

declare
cursor emp_names is
select * from employees;
begin
  for emp_names_row in emp_names loop
    if name = 'aaron' then

       do_stuff_here;
    end if;
  end loop;
end;
/

If you want to start at the name aaron and affect all rows retrieved after that, it's similar:

declare
v_on_or_after_aaron_row boolean := FALSE; cursor emp_names is
select * from employees;
begin
  for emp_names_row in emp_names loop
    if name = 'aaron' then
      v_on_or_after_aaron_row := TRUE;
    end if;
    if v_on_or_after_aaron_row then

       do_stuff_here;
    end if;
  end loop;
end;
/

If you're looking to send output to the screen, do a "set serveroutput on" before the "declare" and use dbms_output.put_line(<some character or variable value here>); to send stuff to the screen.

-Matt Received on Sun Jun 18 2000 - 00:00:00 CEST

Original text of this message