oracle USING 用法
提问
- using(xx)中可以接多个列吗?
- using(xx)中的列可以接表名或别名吗?
- 在使用using的语句中,select * 可以使用吗?
- 如果表有别名t,select t.* from table1 t , table2 using(xx),t.* 可以使用吗?
- left join, right join, inner join, full outer join 可以和using一起用吗?
我们看下语法就能知道答案了。
只看答案
- using(xx)中可以接多个列,它是一种等值连接,可以转换为 join ... on (x=y and xx=y);
- using(xx)中的列不可以接表名或别名等限定语,默认就是指共同列,不能指定表名;
- 在使用using的语句中,select * 可以使用,* 被扩展的顺序为using中的列,左表中的其它列,右表中的其它列
- 如果表有别名t,select t.* from table1 t , table2 using(xx),t.* 不可以使用,using中的列不能加限定词
- left join, right join, inner join, full outer join 可以和using一起使用,它就是简单的等值连接
inner join 就是 join, outer join有 left, right, full outer join 三种
using的使用条件是两表中列名和类型相同;
natural join更进一步,直接省掉了using,但作用和使用using相似;
inner 和 outer 的区别:内连接只返回匹配行,外连接还返回不满足条件的行;
Syntax
USING ( Simple-column-Name [ , Simple-column-Name ]* )
USING clause definition
The USING clause specifies which columns to test for equality when two tables are joined. It can be used instead of an ON clause in the JOIN operations that have an explicit join clause.
If a column in the USING clause is referenced without being qualified by a table name, the column reference points to the column in the first (left) table if the join is an INNER JOIN or a LEFT OUTER JOIN. If it is a RIGHT OUTER JOIN, unqualified references to a column in the USING clause point to the column in the second (right) table.
When a USING clause is specified, an asterisk (*) in the select list of the query will be expanded to the following list of columns (in this order):
- All the columns in the USING clause
- All the columns of the first (left) table that are not specified in the USING clause
- All the columns of the second (right) table that are not specified in the USING clause
Examples
SELECT * FROM COUNTRIES JOIN CITIES
USING (COUNTRY);
SELECT * FROM COUNTRIES JOIN CITIES
USING (COUNTRY, COUNTRY_ISO_CODE);
SELECT * FROM oe.order_items oi JOIN oe.orders o
USING(order_id);
select t.* from hr.employees t, hr.departments d
where t.department_id = d.department_id;
select * from hr.employees t inner join hr.departments d
using(department_id);
select * from hr.employees t left outer join hr.departments d
using(department_id);
select * from hr.employees t right outer join hr.departments d
using(department_id);
select * from hr.employees t full outer join hr.departments d
using(department_id);
oracle USING 用法的更多相关文章
- ORACLE RETURNING 用法总结
ORACLE RETURNING 用法总结 场景 在存储过程.PL/SQL块里需要返回INSERT.DELETE.UPDATE.MERGE等DML语句执行后的信息时使用,合理使用returning能够 ...
- Oracle instr用法
1:实现indexOf功能,.从第1个字符开始,搜索第1次出现子串的位置 ,) as i from dual; select instr('oracle','or') as i from dual; ...
- Oracle minus用法详解及应用实例
本文转载:https://blog.csdn.net/jhon_03/article/details/78321937 Oracle minus用法 “minus”直接翻译为中文是“减”的意思,在Or ...
- Oracle触发器用法实例详解
转自:https://www.jb51.net/article/80804.htm. 本文实例讲述了Oracle触发器用法.分享给大家供大家参考,具体如下: 一.触发器简介 触发器的定义就是说某个条件 ...
- ORACLE SEQUENCE用法(转)
ORACLE SEQUENCE用法 在oracle中sequence就是序号,每次取的时候它会自动增加.sequence与表没有关系. 1.Create Sequence 首先要有CREATE ...
- [转载]Oracle触发器用法实例详解
本文实例讲述了Oracle触发器用法.分享给大家供大家参考,具体如下: 一.触发器简介 触发器的定义就是说某个条件成立的时候,触发器里面所定义的语句就会被自动的执行. 因此触发器不需要人为的去调用,也 ...
- Oracle数据库用法汇总
一些Oracle数据库用法的小总结 1.使用insert into创建新表 insert into destdb.sub_contract (userid,contractid) select msi ...
- oracle sqlloader 用法
向oracle中导入*.csv文件 1.什么是*.csv,如何得到? 里面存放的是数据表.每行代表数据库表格的一行, 每行中,每两个数据中间由逗号","分割. *.csv可以通 ...
- Oracle Hint 用法
正确的语法是: select /*+ index(x idx_t) */ * from t x where x.object_id=123 /*+ */ 和注释很像,比注释多了一个“+”,这就是 ...
- Oracle REGEXP_INSTR 用法
原文出处 ORACLE中的支持正则表达式的函数主要有下面四个: 1,REGEXP_LIKE :与LIKE的功能相似 2,REGEXP_INSTR :与INSTR的功能相似 3,REG ...
随机推荐
- 踏上编程大道 从 Python 开始成为神级 Coder
电脑科学,或说计算机科学,是个在美国不断成长的产业,薪资报酬也很高.市场上永远存在著对天赋异禀的新锐工程师的需求,这就是为什麽「学习程式语言」一直是一件有魅力的事情. 但是,就跟任何技能一样,我们常常 ...
- MariaDB/MySQL备份和恢复(二):数据导入、导出
MariaDB/MySQL备份恢复系列: 备份和恢复(一):mysqldump工具用法详述 备份和恢复(二):导入.导出表数据 备份和恢复(三):xtrabackup用法和原理详述 1.导出.导入数据 ...
- Perl和操作系统交互(一):system、exec和反引号
调用操作系统命令:system函数 system函数可以直接让perl调用操作系统中的命令并执行. system入门示例 例如: #!/usr/bin/perl system 'date +" ...
- 前端(五)之display 总结与浮动
前端之浮动布局.清浮动 display 总结 <!DOCTYPE html> <html> <head> <meta charset="UTF-8& ...
- c# 对JSON字符串排序(KEY/VALUE)
public string StortJson(string json) { var dic = JsonConvert.DeserializeObject<SortedDictionary&l ...
- DataTable与List<T>相互转换
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 如何让gitbook与github仓库关联
一.账号注册 分别https://legacy.gitbook.com/login和https://github.com/注册账号. https://legacy.gitbook.com/login登 ...
- VS2013 添加控制台程序
一.打开vs2013
- 51nod1238 最小公倍数之和 V3(莫比乌斯反演)
题意 题目链接 Sol 不想打公式了,最后就是求一个 \(\sum_{i=1}^n ig(\frac{N}{i})\) \(g(i) = \sum_{i=1}^n \phi(i) i^2\) 拉个\( ...
- 简析服务端通过geotools导入SHP至PG的方法
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 项目中需要在浏览器端直接上传SHP后服务端进行数据的自动入PG ...