Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: SQL Query Help
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
![]() |
![]() |