SQL alias parsing (reprint)

Source: Internet
Author: User
Tags aliases

By using SQL, you can specify aliases (alias) for column names and table names.

In fact, there are three ways to alias the Select column, and these three methods are not applicable to all databases.

Method one, directly after the field name alias, the middle is separated by a space.

Method Two, specify the field alias with the AS keyword, as between the field of the select and the alias.

When an alias is not enclosed in double quotation marks, it displays the result in uppercase. If the alias contains special characters, or if you want the aliases to appear as they are, you will enclose the aliases in double quotation marks.

Select Empno as "Employee number", ename name, (sal+500) *12 "annual Salary" from EMP;

Method three, for SQL Server also provides another method, with the "=" number is specified. The "=" number is placed between the field and the alias of the Select.

Example:

SQL Server Oracle

Select emp_id as EmpId

, emp_name "Employee Name"

, Extemsion=ext

, SUBSTRING (emp_id,1.2) "to job year"

From Employee

where dept_id= ' I200 '

Select emp_id as EmpId

, emp_name "Employee Name"

, Extemsion Ext

, SUBSTR (emp_id,1.2) "to job year"

From Employee

where dept_id= ' I200 '

In an Oracle database, a data table alias cannot be added as, for example:

Select A.appname from AppInfo a;--correct

Select A.appname from appinfo as a;--error

Note: This may be a problem in order to prevent a conflict with the keyword as in a stored procedure in an Oracle database.

http://blog.163.com/magicc_love/blog/static/185853662201210161442254/

SQL alias parsing (reprint)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.