ImageVerifierCode 换一换
格式:PPT , 页数:31 ,大小:343.50KB ,
资源ID:315630      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-315630.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(oracle官方基础教程第18讲(经典版).ppt)为本站会员(无敌)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

oracle官方基础教程第18讲(经典版).ppt

1、,Advanced Subqueries,Objectives,After completing this lesson, you should be able to do the following:Write a multiple-column subqueryDescribe and explain the behavior of subqueries when null values are retrievedWrite a subquery in a FROM clauseUse scalar subqueries in SQLDescribe the types of proble

2、ms that can be solved with correlated subqueriesWrite correlated subqueriesUpdate and delete rows using correlated subqueriesUse the EXISTS and NOT EXISTS operatorsUse the WITH clause,What Is a Subquery?,A subquery is a SELECT statement embedded in a clause of another SQL statement.,SELECT . FROM .W

3、HERE .,(SELECT . FROM . WHERE .),Mainquery,Subquery,Subqueries,The subquery (inner query) executes once before the main query.The result of the subquery is used by the main query (outer query).,SELECTselect_listFROMtableWHEREexpr operator (SELECT select_list FROM table);,SELECT last_nameFROM employe

4、esWHERE salary (SELECT salary FROM employees WHERE employee_id = 149) ;,Using a Subquery,Multiple-Column Subqueries,Main query,WHERE (MANAGER_ID, DEPARTMENT_ID) IN,Subquery,100 90102 60124 50,Each row of the main query is compared to values from a multiple-row and multiple-column subquery.,Column Co

5、mparisons,Column comparisons in a multiple-column subquery can be: Pairwise comparisons Nonpairwise comparisons,Pairwise Comparison Subquery,Display the details of the employees who are managed by the same manager and work in the same department as the employees with EMPLOYEE_ID 178 or 174.,SELECTem

6、ployee_id, manager_id, department_idFROMemployeesWHERE (manager_id, department_id) IN (SELECT manager_id, department_id FROM employees WHERE employee_id IN (178,174)ANDemployee_id NOT IN (178,174);,Nonpairwise Comparison Subquery,SELECT employee_id, manager_id, department_idFROM employeesWHERE manag

7、er_id IN (SELECT manager_id FROM employees WHERE employee_id IN (174,141)AND department_id IN (SELECT department_id FROM employees WHERE employee_id IN (174,141)ANDemployee_id NOT IN(174,141);,Display the details of the employees who are managed by the same manager as the employees with EMPLOYEE_ID

8、174 or 141 and work in the same department as the employees with EMPLOYEE_ID 174 or 141.,SELECT a.last_name, a.salary, a.department_id, b.salavgFROM employees a, (SELECT department_id, AVG(salary) salavg FROM employees GROUP BY department_id) bWHERE a.department_id = b.department_idAND a.salary b.sa

9、lavg;,Using a Subquery in the FROM Clause,Scalar Subquery Expressions,A scalar subquery expression is a subquery thatreturns exactly one column value from one row.Scalar subqueries were supported in Oracle8i only in a limited set of cases, For example:SELECT statement (FROM and WHERE clauses)VALUES

10、list of an INSERT statementIn Oracle9i, scalar subqueries can be used in:Condition and expression part of DECODE and CASEAll clauses of SELECT except GROUP BY,Scalar Subqueries: Examples,Scalar Subqueries in CASE Expressions,SELECT employee_id, last_name, (CASE WHEN department_id = THEN Canada ELSE

11、USA END) locationFROM employees;,(SELECT department_id FROM departmentsWHERE location_id = 1800),Scalar Subqueries in ORDER BY Clause,SELECT employee_id, last_nameFROM employees eORDER BY,(SELECT department_name FROM departments d WHERE e.department_id = d.department_id);,Hidden Slide,Correlated Sub

12、queries,Correlated subqueries are used for row-by-rowprocessing. Each subquery is executed once forevery row of the outer query.,GETcandidate row from outer query,EXECUTEinner query using candidate row value,USEvalues from inner query to qualify or disqualify candidate row,Correlated Subqueries,SELE

13、CT column1, column2, . FROM table1 WHERE column1 operator (SELECT colum1, column2 FROM table2 WHERE expr1 = .expr2);,The subquery references a column from a table in the parent query.,outer,outer,SELECT last_name, salary, department_idFROM employees outerWHERE salary ,Using Correlated Subqueries,Eac

14、h time a row from the outer queryis processed, theinner query isevaluated.,Find all employees who earn more than the average salary in their department.,(SELECT AVG(salary) FROM employees WHERE department_id = outer.department_id) ;,Using Correlated Subqueries,SELECT e.employee_id, last_name,e.job_i

15、dFROM employees e WHERE 2 (SELECT dept_avg FROM avg_cost)ORDER BY department_name;,Summary,In this lesson, you should have learned the following: A multiple-column subquery returns more than one column.Multiple-column comparisons can be pairwise or nonpairwise.A multiple-column subquery can also be

16、used in the FROM clause of a SELECT statement.Scalar subqueries have been enhanced inOracle9i.,Summary,Correlated subqueries are useful whenever a subquery must return a different result for each candidate row.The EXISTS operator is a Boolean operator that tests the presence of a value.Correlated su

17、bqueries can be used with SELECT, UPDATE, and DELETE statements.You can use the WITH clause to use the same query block in a SELECT statement when it occurs more than once,Practice 18 Overview,This practice covers the following topics:Creating multiple-column subqueriesWriting correlated subqueriesUsing the EXISTS operatorUsing scalar subqueriesUsing the WITH clause,

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报