【转】oracle using --OCP-047-34

34. View the Exhibit and examine the structure of the ORDERS and ORDER_ITEMS tables. 

Evaluate the following SQL statement: 

SELECT oi.order_id, product_id, order_date 

FROM order_items oi JOIN orders o

USING(order_id); 

Which statement is true regarding the execution of this SQL statement? 

A. The statement would not execute because table aliases are not allowed in the JOIN clause. 

B. The statement would not execute because the table alias prefix is not used in the USING clause. 

C. The statement would not execute because all the columns in the SELECT clause are not prefixedwith table aliases. 

D. The statement would not execute because the column part of the USING clause cannot have a qualifier in the SELECT list. 

Answer: D

分析上面这道题,要理解using关键字的用法:

     在oralce中使用natural join,也就是自然连接。
     使用natraul join进行连接查询,并且两张表中如果有多个字段是具有相同的名称和数据类型的,那么这些字段都将被oracle自作主张的将他们连接起来。但实际上我们有时候是不需要这样来连接的。我们只需要将他们的多个具有相同的名称和数据类型的字段中挑选一两个。这时候我们就需要用到using 关键字了。在Oracle中的join连接中使用using关键字,是相对于natural join的。
 
先看自然连接:
select ename, dname
from emp natural join dept
/
这时无需指定连接字段,oracle会自动识别相同的字段并自动进行连接,该例中会自动连接deptno字段。
当然,如果这两个表有多个相同字段,那oracle会把它们都做一个连接。
 
使用using关键字
select ename,dname
from emp join dept using (deptno)
/
明确的指定连接字段。
 
注意事项:
1、如果在使用using关键字时,而且select的结果列表项中包含了using关键字所指明的那个关键字,那么请不要在select的结果列表项中对该关键字指明它属于哪个表。
2、using中仅能使用一个列名。
3、natural join关键字和using关键字是互斥的,也就是说不能同时出现。
 
显然,选项D是正确的,因为示例语句中的USING(order_id)这列在select语句中使用了限定词。
 
来源:http://www.cuug.com/xueyuanzhuanqu/jishuwenzhang/201110/jishuwenzhang-1109.html

转载于:https://www.cnblogs.com/Peyton-for-2012/archive/2013/01/09/2853547.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值