版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、Writing Basic SQL StatementsObjectivesAfter completing this lesson, you should be able to do the following:List the capabilities of SQL SELECT statementsExecute a basic SELECT statementDifferentiate between SQL statements and SQL*Plus commandsCapabilities of SQL SELECT StatementsSelectionProjectionT
2、able 1Table 2Table 1Table 1JoinBasic SELECT StatementSELECTDISTINCT *, column alias,.FROMtable;SELECT identifies what columnsFROM identifies which tableWriting SQL StatementsSQL statements are not case sensitive. SQL statements can be on one ormore lines.Keywords cannot be abbreviated or split acros
3、s lines.Clauses are usually placed onseparate lines.Tabs and indents are used to enhance readability. Selecting All Columns DEPTNO DNAME LOC- - - 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTONSQL SELECT * 2 FROM dept; Selecting Specific Columns DEPTNO LOC- - 10 NEW Y
4、ORK 20 DALLAS 30 CHICAGO 40 BOSTONSQL SELECT deptno, loc 2 FROM dept;Column Heading DefaultsDefault justificationLeft: Date and character dataRight: Numeric dataDefault display: UppercaseArithmetic ExpressionsCreate expressions on NUMBER and DATE data by using arithmetic operators.Operator+-* / Desc
5、riptionAddSubtract Multiply Divide Using Arithmetic Operators SQL SELECT ename, sal, sal+300 2 FROMemp;ENAME SAL SAL+300- - -KING 5000 5300BLAKE 2850 3150CLARK 2450 2750JONES 2975 3275MARTIN 1250 1550ALLEN 1600 1900.14 rows selected.Operator PrecedenceMultiplication and division take priority over a
6、ddition and subtraction.Operators of the same priority are evaluated from left to right.Parentheses are used to force prioritized evaluation and to clarify statements.*/+_ Operator PrecedenceSQL SELECT ename, sal, 12*sal+100 2 FROM emp;ENAME SAL 12*SAL+100- - -KING 5000 60100BLAKE 2850 34300CLARK 24
7、50 29500JONES 2975 35800MARTIN 1250 15100ALLEN 1600 19300.14 rows selected. Using ParenthesesSQL SELECT ename, sal, 12*(sal+100) 2 FROM emp;ENAME SAL 12*(SAL+100)- - -KING 5000 61200BLAKE 2850 35400CLARK 2450 30600JONES 2975 36900MARTIN 1250 16200.14 rows selected. Defining a Null ValueA null is a v
8、alue that is unavailable, unassigned, unknown, or inapplicable.A null is not the same as zero or a blank space.SQL SELECT ename, job, comm 2 FROMemp;ENAME JOB COMM- - -KING PRESIDENTBLAKE MANAGER.TURNER SALESMAN 0.14 rows selected. Null Values in Arithmetic ExpressionsArithmetic expressions containi
9、ng a null value evaluate to null.SQL select ename NAME, 12* m 2 from emp 3 WHERE ename=KING;NAME 12* M - -KINGDefining a Column AliasRenames a column headingIs useful with calculationsImmediately follows column name; optional AS keyword between column name and aliasRequires double quotation marks if
10、 it contains spaces or special characters or is case sensitive Using Column Aliases SQL SELECT ename AS name, sal salary 2 FROM emp;NAME SALARY- -.SQL SELECT ename Name, 2 sal*12 Annual Salary 3 FROM emp; Name Annual Salary- -.Concatenation OperatorConcatenates columns or character strings to other
11、columns Is represented by two vertical bars (|)Creates a resultant column that is a character expressionUsing the Concatenation OperatorSQL SELECTename|job AS Employees 2 FROM emp;Employees-KINGPRESIDENTBLAKEMANAGERCLARKMANAGERJONESMANAGERMARTINSALESMANALLENSALESMAN.14 rows selected.Literal Characte
12、r StringsA literal is a character, expression, or number included in the SELECT list.Date and character literal values must be enclosed within single quotation marks.Each character string is output once for each row returned.Using Literal Character StringsEmployee Details-KING is a PRESIDENTBLAKE is
13、 a MANAGERCLARK is a MANAGERJONES is a MANAGERMARTIN is a SALESMAN.14 rows selected.SQL SELECT ename| |is a| |job 2 AS Employee Details 3 FROM emp; Duplicate RowsThe default display of queries is all rows, including duplicate rows.SQL SELECT deptno 2 FROM emp; DEPTNO- 10 30 10 20.14 rows selected. E
14、liminating Duplicate RowsEliminate duplicate rows by using the DISTINCT keyword in the SELECT clause.SQL SELECT DISTINCT deptno 2 FROM emp; DEPTNO- 10 20 30 SQL and SQL*Plus InteractionSQL*PlusSQL StatementsBufferSQL StatementsServerQuery ResultsSQL*Plus CommandsFormatted ReportSQL Statements Versus
15、 SQL*Plus Commands SQLstatementsSQL A languageANSI standardKeyword cannot be abbreviatedStatements manipulate data and table definitions in the databaseSQL*PlusAn environmentOracle proprietaryKeywords can be abbreviatedCommands do not allow manipulation of values in the databaseSQLbufferSQL*Pluscomm
16、andsSQL*PlusbufferLog in to SQL*Plus.Describe the table structure.Edit your SQL statement.Execute SQL from SQL*Plus.Save SQL statements to files and append SQL statements to files.Execute saved files.Load commands from file to bufferto edit.Overview of SQL*PlusLogging In to SQL*PlusFrom Windows envi
17、ronment: From command line: sqlplus username/password databaseDisplaying Table StructureUse the SQL*Plus DESCRIBE command to display the structure of a table.DESCRIBE tablenameDisplaying Table StructureSQL DESCRIBE deptName Null? Type- - -DEPTNO NOT NULL NUMBER(2)DNAME VARCHAR2(14)LOC VARCHAR2(13)SQL*Plus Editing CommandsAPPEND textCHANGE / old / newCHANGE / text /CLEAR BUFFERDELDEL nDEL m nSQL*Plus Editing CommandsINPUTINPUT textLISTLIST nLIST m n RUN n n text0 textSQL*Plus File CommandsSAVE filenameGET filenameSTART filename filenameEDIT filenameSPOOL filenameSummaryUse SQ
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024鋪面租賃合同模板:適用于商業(yè)地產(chǎn)租賃3篇
- 二零二五年度鏟車租賃及運輸配送服務(wù)合同2篇
- 二零二四醫(yī)療期間勞動合同履行與員工職業(yè)規(guī)劃指導(dǎo)協(xié)議3篇
- 2024美團外賣平臺商家合作合同版B版
- 2025年度工業(yè)用地承包租賃合同書3篇
- 2025年度標(biāo)準(zhǔn)夫妻離婚財產(chǎn)分割協(xié)議書3篇
- 2025年度勞動合同試用期員工培訓(xùn)與發(fā)展計劃合同3篇
- 《辦公用房租賃合同》范本
- 二零二五年度智能化工程合同執(zhí)行與風(fēng)險評估策略3篇
- 年度飛機及配件競爭策略分析報告
- SBT11229-2021互聯(lián)網(wǎng)舊貨交易平臺建設(shè)和管理規(guī)范
- 如何打造頂尖理財顧問團隊
- 土壤農(nóng)化分析課件
- 小區(qū)大型團購活動策劃
- NEC(新生兒壞死性小腸結(jié)腸炎)92273
- 2023年租賃風(fēng)控主管年度總結(jié)及下一年展望
- 開關(guān)插座必看的七個安全隱患范文
- 高分子成型加工課件
- 消防救援-低溫雨雪冰凍惡劣天氣條件下災(zāi)害防范及救援行動與安全
- 硅石項目建議書范本
- 概率論在金融風(fēng)險評估中的應(yīng)用研究
評論
0/150
提交評論