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的更多相关文章
随机推荐
- bzoj 1005: [HNOI2008]明明的烦恼 树的prufer序列+万进制
题目传送门 思路: 这道题需要前置知识prufer编码,这篇博客对prufer编码和这道题的分析写的很好. 这里主要讲一些对大数阶乘的分解,一个办法当然是用高精度,上面这篇博客用的是java,还有一个 ...
- bzoj1079 着色方案 记忆化搜索(dp)
题目传送门 题目大意: 有k种颜色,每个颜色ci可以涂个格子,要求相邻格子颜色不能一样,求方案数.ci<=5,k<=15. 思路: 题目里最重要的限制条件是相邻格子颜色不能相同,也就是当前 ...
- java的Spring学习2- junit和mock
<!-- 引用Mock --> <dependency> <groupId>org.mockito</groupId> <artifactId&g ...
- java 读取 xlsx
package test; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream ...
- 【总结】MYSQL注入
关于MYSQL注入的总结,网上的资料很多,这里和大家简单分享下自己实战中常用的思路和命令 0x00 UNION联合查询型注入常用语句 order by n //定字段,n为正整数 union se ...
- Union Find - 20181102 - 20181105
Union Find: 589. Connecting Graph public class ConnectingGraph { //父节点数组 private int[] father = null ...
- oracle 备份恢复篇(一)---rman
一,rman介绍 RMAN(Recovery Manager)是随Oracle服务器软件一同安装的工具软件,它可以用来备份和恢复数据库文件.归档日志和控制文件,用来执行完全或不完全的数据库恢复.与传统 ...
- HTML5之WebSocket && https://zhuanlan.zhihu.com/p/23467317
在认识websocket之前,我们必须了解的是websocket有什么用? 他能解决我们遇到的什么问题? 如果没用,那么我们就么有使用它的必要的. websocket就是建立起全双工协议的,提高了效率 ...
- 【问题记录】 Linux 安装 apache 遇到的一些问题
以下为linux上安装apache时自己遇到的一些问题,记录在这,以后遇到时也会不定时更新... 一.安装Apache提示APR not found的解决办法 解决方法: 1. 网站 http://a ...
- 深度学习(五)基于tensorflow实现简单卷积神经网络Lenet5
原文作者:aircraft 原文地址:https://www.cnblogs.com/DOMLX/p/8954892.html 参考博客:https://blog.csdn.net/u01287127 ...