Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Problems with CAST and order by
"Francesco S. Rinaldi" wrote:
> I have this problem:
> This query is working:
> select distinct cast(history.object_id as varchar(14)),
> object_assembly.object, history.center from history, object_assembly where
> history.object_id like '30210314%' and history.object_id =
> object_assembly.object_id
>
> But I need to order the results by object_id, and it's not working.
> If I try simply to add
> order by object_id
> I get the following error message:
> DB: ERROR: ORA-00918 column ambiguosly defined
> The same error I get if I add
> order by cast(object_id as varchar(14))
> while if i try
> order by history.object_id
> I get
> DB: ERROR: ORA-01791 not a SELECTed expression
>
> How to solve this ?
>
> Thanks in advance,
> Francesco
Alias the column to which you have applied the CAST function.
For example:
select distinct cast(history.object_id as varchar(14)) CASTOBJID
Then order by CASTOBJID
Daniel Morgan Received on Thu Jan 16 2003 - 11:50:50 CST