Re: Two questions about views

From: Thomas J Kyte <tkyte_at_us.oracle.com>
Date: 1996/04/25
Message-ID: <4los8p$3ve_at_inet-nntp-gw-1.us.oracle.com>#1/1


badri_at_cc.gatech.edu (badri) wrote:

>Hi:
 

>1) ORDER BY and views
> I am creating a view and need to have an order by statement.
>If I try it, it does not work. How do I make this to work?

Order by does not work in views. A view is much like a table, it has no order. One way to trick it (a slow way) would be to use group by. Say you had a table and wanted a view that would order by a, b. You could:

create view V
as
select a, b, c, d
from T
group by a, b, c, d

The group by will force a sort. *Warning* I do not recommend doing this unless you will only ever be selecting from the View and not joining/etc this view to other objects. Even if you are just selecting from the view, this is not going to be as good as

create view V
as
select a, b, c, d
from T

select * from V order by a, b

>2) Formatting Numbers and Views
> One of thefields I am selecting is a number and I want it
>to be nicely formatted with commas. How do I do this?

create view X
as
select to_char( some_number_field, '999,999,999.999' ) some_number_field from T

>thanks a lot,
 

>-Badri

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government



opinions and statements are mine and do not necessarily reflect the opinions of Oracle Corporation. Received on Thu Apr 25 1996 - 00:00:00 CEST

Original text of this message