什么是inline view?

其实很简单.   inline view 就是指 from 后面出现另1个select 语句.

例如最简单的inline view 用法

select table_name from (select * from user_tables)

当然上面的inline view用法很多余

让我们看看下面的例子:

19.View the Exhibit and examine PRODUCTS and ORDER_ITEMS tables. You executed the following query to display PRODUCT_NAME and the number of times the product has been ordered:
SELECT p.product_name, i.item_cnt FROM (SELECT product_id, COUNT (*) item_cnt FROM order_items GROUP BY product_id) i RIGHT OUTER JOIN products p ON i.product_id = p.product_id;
What would happen when the above statement is executed?
A. The statement would execute successfully to produce the required output.
B. The statement would not execute because inline views and outer joins cannot be used together.
C. The statement would not execute because the ITEM_CNT alias cannot be displayed in the outer query.
D. The statement would not execute because the GROUP BY clause cannot be used in the inline view.

我们来做个实践

首先建表和插入数据

create table products(product_id number(4),product_name varchar2(20));create table order_items(order_id number(4),product_id number(4),qty number(4),unit_price number(6));insert into products select 1, 'Inkjecet C/8/HQ' from dual;
insert into products select 2, 'CPU D300' from dual;
insert into products select 3, 'HD 8GB/I' from dual;
insert into products select 4, 'HD 12GB/R' from dual;
commit;insert into order_items select 11,1,10,100 from dual;
insert into order_items select 22,2,15,120 from dual;
insert into order_items select 33,3,10,50 from dual;
insert into order_items select 44,1,5,10 from dual;
insert into order_items select 66,2,20,125 from dual;
commit;

在分析下题目中的select 语句:

SQL>  select product_id, count(1) item_cnt from order_items group by product_id;PRODUCT_ID   ITEM_CNT
---------- ----------1      22      23      1SQL> 

select p.product_name, i.item_cnt
from  (select product_id, count(1) item_cnt
        from   order_items
        group by product_id) i right outer join products p
                                              on   p.product_id = i.product_id

可见 红色的select 语句部分被作为1个别称为 i 的表 与  products 表 右连接.

红色部分的执行结果:

SQL>  select product_id, count(1) item_cnt from order_items group by product_id;PRODUCT_ID   ITEM_CNT
---------- ----------1      22      23      1SQL> 

表 products的数据

PRODUCT_ID PRODUCT_NAME
---------- --------------------1 Inkjecet C/8/HQ2 CPU D3003 HD 8GB/I4 HD 12GB/RSQL>

所以右连接后. (右边的数据无对应左边数据的话显示右边的数据)

就成为:

PRODUCT_NAME        ITEM_CNT
-------------------- ----------
Inkjecet C/8/HQ           2
CPU D300              2
HD 8GB/I              1
HD 12GB/R

所以题目的select 语句是能正确执行的.

答案是A

Oracle inline view 简介相关推荐

  1. ORACLE内存结构简介

    ORACLE数据库作为世界上一款功能强大的数据库管理软件,功能体系特别庞大.我们有必要对它的每一部分学习了解,然后才从全局的角度进行有效把握.我们会着重从理论基础体系角度再逐步到实战应用.实际上,如果 ...

  2. C++ inline 函数简介

    1.inline 函数简介 inline 函数由 inline 关键字定义,引入 inline 函数的主要原因是用它替代 C 中复杂易错不易维护的宏函数. 2.编译器对 inline 函数的处理办法 ...

  3. oracle bam教程,Oracle BAM原理简介

    Oracle BAM原理简介 Oracle BAM全称为Oracle Busines Activity Monitoring,中文叫Oracle 业务活动监视 ,BAM有两种功能 1.创建实时repo ...

  4. C++inline函数简介

    1.inline函数简介 inline函数是由inline关键字来定义,引入inline函数的主要原因是用它替代C中复杂易错不易维护的宏函数. inline(小心,不是online),翻译成" ...

  5. oracle视图view看不出来主键,oracle - 使用主键创建视图

    简单的答案是你的语法不正确.您必须指定DISABLE. NOVALIDATE禁用主键验证,在视图中这是默认值,因此自动包含;但是如果你使用它会更清楚,因为在一个可爱的双重否定中,disable nov ...

  6. oracle 创建view时,授权给用户

    解决方法: 以dba用户登录 sqlplus / as sysdba 赋予scott用户创建VIEW的权限 grant create view to scott 以scott用户登录oracle co ...

  7. Oracle public view,【易错概念】以太坊Solidity函数的external/internal,public/private,view/pure/payable区别...

    1. 函数类型:内部(internal)函数和外部(external)函数 函数类型是一种表示函数的类型.可以将一个函数赋值给另一个函数类型的变量,也可以将一个函数作为参数进行传递,还能在函数调用中返 ...

  8. Oracle(一):简介、安装、DDL、DML、JDBC、导入导出

    一.ORACLE 简介 (一)什么是 ORACLE ORACLE 数据库系统是美国 ORACLE 公司(甲骨文)提供的以分布式数据库为核心的一组软件产品,是目前最流行的客户/服务器(CLIENT/SE ...

  9. oracle grant view access,oracle中v$access视图介绍

    如果想了解如果杀掉一个正在运行的存储过程,请查询这篇文章: oracle杀掉一个正在运行的数据对象: 外链网址已屏蔽 可以利用此视图的v$session视图配合使用,来杀掉一个正在运行的数据库对象(比 ...

最新文章

  1. python简单程序代码-有那些用python修改python程序代码的简单方法?
  2. Android6.0以上的权限问题
  3. 吴恩达的 CS229,有人把它浓缩成 6 张中文速查表!
  4. 23种设计模式及OOP7大原则
  5. ux和ui_如何为您的UX / UI设计选择正确的原型制作工具
  6. idea创建maven程序_使用Maven程序集创建漏洞评估工件
  7. dz后台html,discuz X1.5 论坛后台站长常用操作小结
  8. 力扣236. 二叉树的最近公共祖先(JavaScript)
  9. 阿里播放器的使用Aliplayer
  10. 远景论坛黑苹果专区_黑苹果扯犊子篇
  11. PADS 不同单位之间的切换
  12. 区块链:以太坊白皮书
  13. win10 使用苹果耳机没有声音解决方案
  14. Zynq LTE基站设计与实现
  15. Github TOC 生成工具
  16. 视觉惯性单目SLAM (二) 算法基础知识
  17. vue源码分析-响应式系统(二)
  18. 绝版珍藏---.net2.0框架老爷机专用
  19. 用户体验的要素pdf_写给设计师的用户体验基础(二)
  20. 这就是不一样的你,不一样的烟火

热门文章

  1. 131. 分割回文串(回溯算法)
  2. itchat群机器人的自动画实现
  3. [How TO]-ubuntu下安装selenium
  4. 2022-03-22
  5. Android的AlertDialog详解
  6. C语音和易语言实现内存补丁
  7. IDEA是否会嫌导jar包麻烦吗???赶快来学习maven吧,冲冲冲
  8. 创业的和想拿高薪的朋友可以看看,企业安全进行云平台运营的5个关键因素
  9. 创建一个HTML文件
  10. 1022 Digital Library (30 分) 【难度: 中 / 知识点: 哈希表】