4a上1it行業(yè)管理策劃寶典les_第1頁
4a上1it行業(yè)管理策劃寶典les_第2頁
4a上1it行業(yè)管理策劃寶典les_第3頁
4a上1it行業(yè)管理策劃寶典les_第4頁
4a上1it行業(yè)管理策劃寶典les_第5頁
已閱讀5頁,還剩33頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論