日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Oracle inline view 简介

發布時間:2025/3/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Oracle inline view 简介 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

什么是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 简介的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。