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的更多相关文章
随机推荐
- 下载 生成 requirements
生成你项目的所有 组件,模块 pip3 freeze > requirements.txt 下载requirements.txt 里的所有 模块 pip3 install -r requirem ...
- P4890 Never·island
传送门 考虑把总区间长度减去最多能减少的区间长度 把所有区间离散化,对每一小段计算贡献 分类讨论一波,对于边界 $i,i+1$ ,设它们之间距离 $d$,$i$ 属于 $x$ 考察队的边界,$i+1$ ...
- Python-is, ==, cmp()
is 主要是判断 2 个变量是否引用的是同一个对象,如果是的话,则返回 true,否则返回 false. 判断数字相等不要用 is 操作符 1 2 3 4 5 6 7 8 9 10 11 12 > ...
- [转] JavaScript中的Truthy和Falsy介绍
[From] http://www.jb51.net/article/59285.htm 与大多数编程语言一样,JavaScript中存在boolean类型,以供逻辑判断使用.不过,和很多其它编程语言 ...
- js中点和向量的基本方法
var Point=function(x,y){ this.x= Number(x.toFixed(2))||0; this.y=Number(y.toFixed(2))||0; } Point.pr ...
- drf的安装和配置
一.安装 1.安装 pip install djangorestframework 2.配置 注:以上两部就OK了 二.最简单的drf版本 1.创建应用 在项目中新建一个应用: python mana ...
- 今日工作总结:jquery轮转效果的集成与前台页面banner的设计思路总结
今日做了两个项目中的两个问题,现在特来总结一下,以便分享给更多的朋友们. 1.jquery轮转效果的集成 涉及到jquery的不同版本问题,解决办法是在后缀用jQuery代替$.项目地址在:121.4 ...
- http和web缓存
1.http的缓存类型 缓 存对于一个网站来说非常重要,可以提高网站性能,减少冗余的数据传输,增加服务器负担,web存储则给浏览器提供了更加强大的保存文件的接口.关于web下的http缓存类型比较 ...
- 【3dsMax安装失败,如何卸载、安装3dMax 2012?】
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- (转)shell--read命令的选项及用法
shell--read命令 原文:https://www.cnblogs.com/lottu/p/3962921.html http://blog.csdn.net/skdkjzz/article/d ...