简体   繁体   中英

Oracle column alias in select: is “AS” mandatory?

Does it make any difference omitting the "AS" before defining the name of a column when creating a new view?

SELECT
T.STUFF   AS MY_STUFF

VS

SELECT
T.STUFF      MY_STUFF

It doesn't make any difference from the DB's point of view. Personally, I prefer the explicit AS and a separate line in my SQL statement per column for a couple of reasons:

  • you can easily search for a given column alias (just grep for AS <alias> )
  • without the AS , you might forget a comma - this results in one aliased column instead of two non-aliased ones. If you always use an AS , you can spot this kind of error more easily

NO , it is just for understandability(readability) purpose.

One would obviously never ever have trouble reading the former with AS. It sounds more logical.

A view is just a stored query , so the select syntax applies. As you can see from the syntax diagram for the select list items:

在此处输入图片说明

... the AS keyword in the expr AS c_alias section is optional. So no, it makes no difference to the query, database or view. It's for readability and consistency with other database systems. I prefer to use it for anything other than a quick ad hoc query, and you may have coding standards that require it, but Oracle does not care.

仅当您计划使用一个别名,且该别名使用多个单词且多个单词之间用空格隔开或一个需要特定类型的情况(例如Employee ID )时,才不需要AS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM