首页 Oracle Pl SQL 04

Oracle Pl SQL 04

举报
开通vip

Oracle Pl SQL 04DisplayingDatafromMultipleTablesObjectivesAftercompletingthislesson,youshouldbeabletodothefollowing:WriteSELECTstatementstoaccessdatafrommorethanonetableusingequalityandnonequalityjoinsViewdatathatgenerallydoesnotmeetajoinconditionbyusingouterjoinsJoinatableto...

Oracle Pl SQL 04
DisplayingDatafromMultipleTablesObjectivesAftercompletingthislesson,youshouldbeabletodothefollowing:WriteSELECTstatementstoaccessdatafrommorethanonetableusingequalityandnonequalityjoinsViewdatathatgenerallydoesnotmeetajoinconditionbyusingouterjoinsJoinatabletoitselfbyusingaselfjoinObtainingDatafromMultipleTablesEMPLOYEESDEPARTMENTS……CartesianProductsACartesianproductisformedwhen:AjoinconditionisomittedAjoinconditionisinvalidAllrowsinthefirsttablearejoinedtoallrowsinthesecondtableToavoidaCartesianproduct,alwaysincludeavalidjoinconditioninaWHEREclause.GeneratingaCartesianProductCartesianproduct:20x8=160rowsEMPLOYEES(20rows)DEPARTMENTS(8rows)……EquijoinNon-equijoinOuterjoinSelfjoinTypesofJoinsCrossjoinsNaturaljoinsUsingclauseFullortwosidedouterjoinsArbitraryjoinconditionsforouterjoinsSQL:1999CompliantJoins:OracleProprietaryJoins(8iandprior):JoiningTablesUsingOracleSyntaxUseajointoquerydatafrommorethanonetable.WritethejoinconditionintheWHEREclause.Prefixthecolumnnamewiththetablenamewhenthesamecolumnnameappearsinmorethanonetable.SELECTtable1.column,table2.columnFROMtable1,table2WHEREtable1.column1=table2.column2;WhatisanEquijoin?EMPLOYEESDEPARTMENTSForeignkeyPrimarykey……SELECTemployees.employee_id,employees.last_name,employees.department_id,departments.department_id,departments.location_idFROMemployees,departmentsWHEREemployees.department_id=departments.department_id;RetrievingRecordswithEquijoins…QualifyingAmbiguousColumnNamesUsetableprefixestoqualifycolumnnamesthatareinmultipletables.Improveperformancebyusingtableprefixes.Distinguishcolumnsthathaveidenticalnamesbutresideindifferenttablesbyusingcolumnaliases.SELECTe.employee_id,e.last_name,e.department_id,d.department_id,d.location_idFROMemployeese,departmentsdWHEREe.department_id=d.department_id;UsingTableAliasesSimplifyqueriesbyusingtablealiases.Improveperformancebyusingtableprefixes.JoiningMorethanTwoTablesEMPLOYEESLOCATIONSDEPARTMENTSTojoinntablestogether,youneedaminimumofn-1joinconditions.Forexample,tojointhreetables,aminimumoftwojoinsisrequired.…Non-EquijoinsEMPLOYEESJOB_GRADESSalaryintheEMPLOYEEStablemustbebetweenlowestsalaryandhighestsalaryintheJOB_GRADEStable.…RetrievingRecordswithNon-EquijoinsSELECTe.last_name,e.salary,j.grade_levelFROMemployeese,job_gradesjWHEREe.salaryBETWEENj.lowest_salANDj.highest_sal;…OuterJoinsEMPLOYEESDEPARTMENTSTherearenoemployeesindepartment190.…OuterJoinsSyntaxYouuseanouterjointoalsoseerowsthatdonotmeetthejoincondition.Theouterjoinoperatoristheplussign(+).SELECTtable1.column,table2.columnFROMtable1,table2WHEREtable1.column(+)=table2.column;SELECTtable1.column,table2.columnFROMtable1,table2WHEREtable1.column=table2.column(+);SELECTe.last_name,e.department_id,d.department_nameFROMemployeese,departmentsdWHEREe.department_id(+)=d.department_id;UsingOuterJoins…SelfJoinsEMPLOYEES(WORKER)EMPLOYEES(MANAGER)MANAGER_IDintheWORKERtableisequaltoEMPLOYEE_IDintheMANAGERtable.……JoiningaTabletoItselfSELECTworker.last_name||'worksfor'||manager.last_nameFROMemployeesworker,employeesmanagerWHEREworker.manager_id=manager.employee_id;…SummaryInthislesson,youshouldhavelearnedhowtousejoinstodisplaydatafrommultipletablesin:Oracleproprietarysyntaxforversions8iandearlierSQL:1999compliantsyntaxforversion9i演讲完毕,谢谢观看!
本文档为【Oracle Pl SQL 04】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
个人认证用户
言言无悔一生
暂无简介~
格式:ppt
大小:413KB
软件:PowerPoint
页数:21
分类:
上传时间:2022-01-21
浏览量:0