資源描述:
《oracle公司內(nèi)部數(shù)據(jù)庫(kù)培訓(xùn)資料》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫(kù)。
1、基本SQLSELECT語(yǔ)句Copyright?OracleCorporation,2001.Allrightsreserved.目標(biāo)通過(guò)本章學(xué)習(xí),您將可以:?列舉SQLSELECT語(yǔ)句的功能。?執(zhí)行簡(jiǎn)單的選擇語(yǔ)句。?SQL語(yǔ)言和SQL*Plus命令的不同。1-2Copyright?OracleCorporation,2001.Allrightsreserved.SQLSELECT語(yǔ)句的功能列行表表Join表1表21-3Copyright?OracleCorporation,2001.Allrightsreserved.
2、基本SELECT語(yǔ)句SELECTSELECT*
3、{[DISTINCT]*
4、{[DISTINCT]columncolumn
5、
6、expressionexpression[[aliasalias],...}],...}FROMFROMtable;table;?SELECT標(biāo)識(shí)選擇哪些列。?FROM標(biāo)識(shí)從哪個(gè)表中選擇。1-4Copyright?OracleCorporation,2001.Allrightsreserved.選擇全部列SELECT*FROMdepartments;1-5Copyright?OracleCorpo
7、ration,2001.Allrightsreserved.選擇特定的列SELECTdepartment_id,location_idFROMdepartments;1-6Copyright?OracleCorporation,2001.Allrightsreserved.WritingSQLStatements?SQL語(yǔ)言大小寫(xiě)不敏感。?SQL可以寫(xiě)在一行或者多行?關(guān)鍵字不能被縮寫(xiě)也不能分行?各子句一般要分行寫(xiě)。?使用縮進(jìn)提高語(yǔ)句的可讀性。1-7Copyright?OracleCorporation,2001.All
8、rightsreserved.列頭設(shè)置?SQL*Plus:–字符和日期類型的列左對(duì)齊–字符類型的列右對(duì)齊–默認(rèn)頭顯示方式:大寫(xiě)1-8Copyright?OracleCorporation,2001.Allrightsreserved.算術(shù)運(yùn)算符數(shù)字和日期使用的數(shù)學(xué)表達(dá)式。操作符描述+加-減*乘/除1-9Copyright?OracleCorporation,2001.Allrightsreserved.使用數(shù)學(xué)運(yùn)算符SELECTlast_name,salary,salary+300FROMemployees;…1-10
9、Copyright?OracleCorporation,2001.Allrightsreserved.操作符優(yōu)先級(jí)___***///+++?乘除的優(yōu)先級(jí)高于加減。?同一優(yōu)先級(jí)運(yùn)算符從左向右執(zhí)行。?括號(hào)內(nèi)的運(yùn)算先執(zhí)行。1-11Copyright?OracleCorporation,2001.Allrightsreserved.操作符優(yōu)先級(jí)SELECTlast_name,salary,12*salary+100FROMemployees;…1-12Copyright?OracleCorporation,2001.Allri
10、ghtsreserved.使用括號(hào)SELECTlast_name,salary,12*(salary+100)FROMemployees;…1-13Copyright?OracleCorporation,2001.Allrightsreserved.定義空值?空值是無(wú)效的,未指定的,未知的或不可預(yù)知的值。?空值不是空格或者0。SELECTlast_name,job_id,salary,commission_pctFROMemployees;……1-14Copyright?OracleCorporation,2001.A
11、llrightsreserved.空值在數(shù)學(xué)運(yùn)算中的使用包含空值的數(shù)學(xué)表達(dá)式的值都為空值SELECTlast_name,12*salary*commission_pctFROMemployees;……1-15Copyright?OracleCorporation,2001.Allrightsreserved.列的別名列的別名:?重命名一個(gè)列。?便于計(jì)算。?緊跟列名,也可以在列名和別名之間加入關(guān)鍵字‘AS’,以便在別名中包含空格或特殊的字符并區(qū)分大小寫(xiě)。1-16Copyright?OracleCorporation,20
12、01.Allrightsreserved.使用別名SELECTlast_nameASname,commission_pctcommFROMemployees;…SELECTlast_name"Name",salary*12"AnnualSalary"FROMemployees;…1-17Copyright?OracleCorpor