Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: SQL Query Help

Re: SQL Query Help

From: Ian Cary <cary_at_gatwick.geco-prakla.slb.com>
Date: 1997/11/26
Message-ID: <347C1306.F3CC95D5@gatwick.geco-prakla.slb.com>#1/1

Wallace Fukumae wrote:

> A tableT has two fields 'fieldA', 'fieldB'. fieldA is a character field
> but contains
> only numbers for priorities. fieldB is a character field identifying the
> record.
> I would like to generate a query which would return rownum,fieldA,fieldB
> from
> tableT but ordered by fieldA. For example, I would like to return the top
> 500 records from tableT.

Wally,
Your best bet would be to use PL/SQL e.g.

declare

cursor read_tab is
select fielda,fieldb
from tab1
order by fieldb;

iter integer := 0;

begin
for rt in read_tab
 loop
   iter := iter +1;
   if iter < 501 then

      dbms_output.put_line(iter||' '||rt.fielda||' '||rt.fieldb);     else
      exit;
  end if;
 end loop;
end;

You could of course use utl_file rather than dbms_output if you need to output directly to a file. It may also be worth using lpad and/or rpad to ensure that the output is correctly aligned.

Hope this helps,

Ian Received on Wed Nov 26 1997 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US