select查詢之六:別名與拼接
在查詢工作中,為了查詢資料的高可讀性,給欄位或組合欄位起一個別名非常重要。
根據人們讀取資料的習慣性,在查詢的資料中,連線符“||”也經常會用到。
1、別名:
1》直接 空格接別名:
SQL> select sal,comm,sal+comm income
2 from emp
3 where comm is not null;
SAL COMM INCOME
---------- ---------- ----------
1600 300 1900
1250 500 1750
1250 1400 2650
1500 0 1500
2》As 別名:
SQL> select sal,comm,sal+comm as income
2 from emp
3 where comm is not null;
SAL COMM INCOME
---------- ---------- ----------
1600 300 1900
1250 500 1750
1250 1400 2650
1500 0 1500
3》直接空格雙引號括起別名:
SQL> select sal,comm,sal+comm "shou ru"
2 from emp
3 where comm is not null;
SAL COMM shou ru
---------- ---------- ----------
1600 300 1900
1250 500 1750
1250 1400 2650
1500 0 1500
4》As 雙引號括起別名:
SQL> select sal,comm,sal+comm as "shou ru"
2 from emp
3 where comm is not null;
SAL COMM shou ru
---------- ---------- ----------
1600 300 1900
1250 500 1750
1250 1400 2650
1500 0 1500
2、 拼接:
拼接:“||”可以拼接多個成分,而函式 concat只能拼接兩個成分。
1》直接使用“||”:
SQL> select 'select * from hr_' || lower(tname) ||';'
2 from tab;
'SELECT*FROMHR_'||LOWER(TNAME)||';'
------------------------------------------------
select * from hr_bonus;
select * from hr_dept;
select * from hr_emp;
select * from hr_employees1;
select * from hr_salgrade;
select * from hr_sl_base;
select * from hr_worker;
7 rows selected.
2》使用 q’[...]’ :
SQL> select last_name || q'['s Salary is:]' ||salary as income
2 from employees;
INCOME
------------------------------------------------------------------------------
OConnell's Salary is:2600
Grant's Salary is:2600
Whalen's Salary is:4400
Hartstein's Salary is:13000
Fay's Salary is:6000
Mavris's Salary is:6500
Baer's Salary is:10000
Higgins's Salary is:12008
Gietz's Salary is:8300
King's Salary is:24000
Kochhar's Salary is:17000
107 rows selected.
3》使用concat:
SQL> select concat('select * from hr_',lower(tname)) ||';'
2 from tab;
CONCAT('SELECT*FROMHR_',LOWER(TNAME))||';'
------------------------------------------------
select * from hr_bonus;
select * from hr_dept;
select * from hr_emp;
select * from hr_employees1;
select * from hr_salgrade;
select * from hr_sl_base;
select * from hr_worker;
7 rows selected.
附:
SELECT deptno, LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees
FROM emp
GROUP BY deptno;
完畢,謝謝觀賞!
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31392094/viewspace-2126000/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- select查詢之四:連線查詢
- Mysql第六講 select查詢基礎篇MySql
- mysql查詢結果多列拼接查詢MySql
- select查詢之五:分析函式在查詢的運用函式
- 【閃回特性之閃回查詢】使用閃回查詢(select as of)
- select查詢之三:子查詢
- select查詢之一:普通查詢
- MySQL查詢取別名報錯MySql
- select子查詢
- select查詢之二:分組與排序排序
- MySQL講義第 47 講——select 查詢之查詢練習(五)MySql
- MySQL講義第27講——select 查詢之自連線查詢MySql
- Mybatis中Oracle的拼接模糊查詢MyBatisOracle
- mysql之查詢使用者名稱MySql
- mysqPoint型別查詢和插入操作:insert和select型別
- Vue請求介面查詢條件拼接Vue
- sql查詢更新update selectSQL
- Select from subquery 子查詢
- 在HQL select查詢語句中自定義查詢結果返回的資料型別資料型別
- 報表名和查詢名之間的命名規範
- MySQL第六篇:索引與子查詢MySql索引
- lavavel 中運算元據庫查詢別名
- oracle 10046與select table查詢表系列(一)Oracle
- [玩轉MySQL之六]MySQL查詢優化器MySql優化
- SQLServer DML操作阻塞SELECT查詢SQLServer
- 查詢之折半查詢
- SQLite中的SELECT子句使用別名SQLite
- MongoDB入門系列(三):查詢(SELECT)MongoDB
- select查詢中union連線符
- oracle trace檔名查詢Oracle
- BSN-DDC基礎網路DDC SDK詳細設計(六):交易查詢、區塊查詢、簽名事件事件
- msyql千萬級別查詢優化之索引優化索引
- 【SQL查詢】集合查詢之INTERSECTSQL
- Oracle閃回查詢,閃回版本查詢與閃回事務查詢的使用區別總結Oracle
- 一條select的查詢的過程
- LINQ系列:LINQ to SQL Select查詢SQL
- 查詢語句(SELECT)的最佳化
- 子查詢中all與any的區別