ORACLE_ALIAS
Oracle / PLSQL: ALIASES
website:https://www.techonthenet.com/oracle/alias.php
This Oracle tutorial explains how to use Oracle ALIASES (temporary names for columns or tables) with syntax and examples.
Description
Oracle ALIASES can be used to create a temporary name for columns or tables.
- COLUMN ALIASES are used to make column headings in your result set easier to read.
- TABLE ALIASES are used to shorten your SQL to make it easier to read or when you are performing a self join (ie: listing the same table more than once in the FROM clause(列出相同的表不止一次在那个from从句)).
Syntax
The syntax to ALIAS A COLUMN in Oracle/PLSQL is:
column_name AS alias_name
OR
The syntax to ALIAS A TABLE in Oracle/PLSQL is:
table_name alias_name
Parameters or Arguments
- column_name
- The original name of the column that you wish to alias.
- table_name
- The original name of the table that you wish to alias.
- alias_name
- The temporary name to assign.
Note
- If the alias_name contains spaces, you must enclose(包围) the alias_name in quotes(双引号).
- if the alias_name contains number,you must enclose then alias_name in quotes.(myself addtion)
- It is acceptable to use spaces when you are aliasing a column name. However, it is not generally good practice to use spaces when you are aliasing a table name.
- The alias_name is only valid within the scope of the SQL statement.
Example - ALIAS a column
Generally, aliases are used to make the column headings in your result set easier to read. For example, when concatenating fields together(连接字段), you might alias the result.
For example:
SELECT contact_id, first_name || last_name AS NAME
FROM contacts
WHERE last_name = 'Anderson';
In this example, we've aliased the second column (ie: first_name and last_name concatenated) as NAME. As a result, NAME will display as the heading for the second column when the result set is returned. Because our alias_name did not include any spaces, we are not required to enclose the alias_name in quotes.
However, it would have been perfectly acceptable to write this example using quotes as follows:
SELECT contact_id, first_name || last_name AS "NAME"
FROM contacts
WHERE last_name = 'Anderson';

Next, let's look at an example where we are required to enclose the alias_name in quotes.
For example:
SELECT contact_id, first_name || last_name AS "CONTACT NAME"
FROM contacts
WHERE last_name = 'Anderson';
In this example, we've aliased the second column (ie: first_name and last_name concatenated) as "CONTACT NAME". Since there are spaces in this alias_name, "CONTACT NAME" must be enclosed in quotes.
Example - ALIAS a Table
When you create an alias on a table, it is either(任何一个) because you plan to list the same table name more than once in the FROM clause (ie: self join), or you want to shorten the table name to make the SQL statement shorter and easier to read.
Let's look at an example of how to alias a table name in Oracle/PLSQL.
For example:
SELECT p.product_id, p.product_name, categories.category_name
FROM products p
INNER JOIN categories
ON p.category_id = categories.category_id
ORDER BY p.product_name ASC, categories.category_name ASC;
In this example, we've created an alias for the products table called p. Now within this SQL statement, we can refer to the products table as p.
When creating table aliases, it is not necessary to create aliases for all of the tables listed in the FROM clause. You can choose to create aliases on any or all of the tables.
For example, we could modify our example above and create an alias for the categories table as well.
SELECT p.product_id, p.product_name, c.category_name
FROM products p
INNER JOIN categories c
ON p.category_id = c.category_id
ORDER BY p.product_name ASC, c.category_name ASC;
Now we have an alias for categories table called c as well as the alias for the products table called p.
ORACLE_ALIAS的更多相关文章
随机推荐
- FFT 深夜摸鱼小笔记
本次笔记学习自算法导论 FFT核心:系数表示→(单位复数根)点值表示→(插值)系数表示 关于单位复数根 n次单位复数根\(ω\)为满足\(ω^n=1\)的复数 n次单位复数根恰好有n个,表示为\(ω_ ...
- 学习掌握oracle外表(external table)
[转自] http://blog.chinaunix.net/uid-10697776-id-2935685.html 定义 External tables access data in extern ...
- vim(一) vim与markdown
vim markdown 配置 vim高亮显示Markdown语法 在.vimrc添加 Plugin 'godlygeek/tabular' Plugin 'plasticboy/vim-markdo ...
- phpstorm 2017 关掉变量提示 parameter name hints
配置面板中搜索 hints 路径 Editor > General > Appearance > Show parameter name hits 去掉前面的勾就行了
- PIE SDK元素的删除
1功能简介 元素删除是将根据需求将不符合的元素进行删除,PIE SDK支持元素的删除操作,下面对元素的删除功能进行介绍. 2功能实现说明 2.1.1 实现思路及原理说明 第一步 获取已经选择的元素 第 ...
- ReactJS 页面跳转保存当前scrollTop回来时,自动移动到上次浏览器的位置
在移动端的操作的时候,相信大家都遇到到这种情况,翻了好几页了,点击一项进去查,然后回来的时候,还想回来我原来的位置. google上也找了一此,有一个组件,但是好像是如果想实现这个功能,页面就得用那个 ...
- 创建本地maven仓库
1.首先从下面地址下载nexus-oss-webapp-2.3.1-01 http://pan.baidu.com/s/1pKOLdbH 2.修改配置文件: 打开:*nexus-oss-webapp- ...
- Iterator遍历 (遍历集合)
迭代器(Iterator) 迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结构.迭代器通常被称为“轻量级”对象,因为创建它的代价小. Java中的I ...
- 【CAD】创建多行文本
下面为OBJECT-ARX创建多行文本的代码,记录 McDbMText* Mx::AddMText(IN McDbBlockTableRecord* pBlkRec, IN LPCTSTR pszCo ...
- innosetup卸载软件后,删除定时任务schedule task
代码如下: //innosetup自带的方法,当卸载软件时,根据卸载的状态改变时而触发 procedure CurUninstallStepChanged(CurUninstallStep: TUni ...