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

Home -> Community -> Usenet -> c.d.o.misc -> Re: as in SQL

Re: as in SQL

From: <prochak_at_my-dejanews.com>
Date: Fri, 18 Dec 1998 18:02:29 GMT
Message-ID: <75e5bj$9j2$1@nnrp1.dejanews.com>


In article <75cafk$bql$1_at_kraken.itc.gu.edu.au>,   c.undieseastwood_at_gu.edu.au (Chris Eastwood) wrote:
> HiYa
>
> I am interested in a piece of SQL that I have just seen, I don't understand
> the need for the AS clause in the select statement.
>
> IE
>
> CREATE TABLE bill
> (
> VERS,
> CAT_NAME,
> ITEM_TYPE,
> ITEM,
> OLD_ITEM,
> ACCNBR_ACC,
> SECMASK1,
> OLD_SECMASK1,
> SECMASK2
> )
> AS <--- I understand this one ...
> SELECT
[note: syntactically the two words belong together "AS SELECT "]
> VERS,
> CAT_NAME,
> ITEM_TYPE,
> replace(ITEM,'98','99') as ITEM, <---- but not this
> ITEM AS OLD_ITEM,
> ACCNBR_ACC,
> replace(SECMASK1, '98','99') as SECMASK1, <--- or this
> SECMASK1 as OLD_SECMASK1,
> SECMASK2
> FROM
> blah blah blah
> );
>
> surely the table bill would be created the positional order of the
> colum names?? Even then the column could be aliased.
>
> Thanks
>
> See Ya
> (when bandwidth gets better ;-)
>
> Chris Eastwood
> Photographer, Programmer email ua.ude.ug.cti_at_doowtsae.c
> Motorcyclist and dingbat WWW http://chrise.itc.gu.edu.au
>

Think about how ORACLE names columns in a select statement and you'll understand why the AS clause is required in the second and third instance. In other words, without the AS clause, the column would be named

REPLACE(ITEM,'98','99') instead of ITEM. It could get tricky to work with that way. 8^)

I hope that helps.

   ed

--
Ed Prochak
Magic Interface, Ltd.
440-498-3702

-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own Received on Fri Dec 18 1998 - 12:02:29 CST

Original text of this message

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