26.oracleocp題庫dba經(jīng)典輔助學(xué)習(xí)les_第1頁
26.oracleocp題庫dba經(jīng)典輔助學(xué)習(xí)les_第2頁
26.oracleocp題庫dba經(jīng)典輔助學(xué)習(xí)les_第3頁
26.oracleocp題庫dba經(jīng)典輔助學(xué)習(xí)les_第4頁
26.oracleocp題庫dba經(jīng)典輔助學(xué)習(xí)les_第5頁
已閱讀5頁,還剩33頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

1、Restricting and Sorting Data ObjectivesAfter completing this lesson, you should be able to do the following:Limit the rows that are retrieved by a querySort the rows that are retrieved by a queryUse ampersand substitution in iSQL*Plus to restrict and sort output at run time Limiting Rows Using a Sel

2、ection“retrieve allemployees in department 90”EMPLOYEESLimiting the Rows That Are SelectedRestrict the rows that are returned by using the WHERE clause:The WHERE clause follows the FROM clause.SELECT *|DISTINCT column|expression alias,.FROM tableWHERE condition(s);SELECT employee_id, last_name, job_

3、id, department_idFROM employeesWHERE department_id = 90 ;Using the WHERE ClauseSELECT last_name, job_id, department_idFROM employeesWHERE last_name = Whalen ;Character Strings and DatesCharacter strings and date values are enclosed by single quotation marks.Character values are case-sensitive, and d

4、ate values are format-sensitive.The default date format is DD-MON-RR.Comparison ConditionsOperatorMeaning=Equal toGreater than=Greater than or equal toLess than=Less than or equal toNot equal toBETWEEN.AND.Between two values (inclusive)IN(set)Match any of a list of values LIKEMatch a character patte

5、rn IS NULLIs a null value SELECT last_name, salaryFROM employeesWHERE salary =10000AND job_id LIKE %MAN% ;Using the AND OperatorAND requires both conditions to be true:SELECT employee_id, last_name, job_id, salaryFROM employeesWHERE salary = 10000OR job_id LIKE %MAN% ;Using the OR OperatorOR require

6、s either condition to be true:SELECT last_name, job_idFROM employeesWHERE job_id NOT IN (IT_PROG, ST_CLERK, SA_REP) ;Using the NOT OperatorRules of PrecedenceYou can use parentheses to override rules of precedence.OperatorMeaning1Arithmetic operators2Concatenation operator3Comparison conditions4IS N

7、OT NULL, LIKE, NOT IN5NOT BETWEEN6Not equal to7NOT logical condition8AND logical condition9OR logical conditionSELECT last_name, job_id, salaryFROM employeesWHERE job_id = SA_REPOR job_id = AD_PRESAND salary 15000;Rules of PrecedenceSELECT last_name, job_id, salaryFROM employeesWHERE (job_id = SA_RE

8、POR job_id = AD_PRES)AND salary 15000;12Using the ORDER BY ClauseSort retrieved rows with the ORDER BY clause:ASC: ascending order, defaultDESC: descending orderThe ORDER BY clause comes last in the SELECT statement:SELECT last_name, job_id, department_id, hire_dateFROM employeesORDER BY hire_date ;

9、SortingSorting in descending order:Sorting by column alias:Sorting by multiple columns:SELECT last_name, job_id, department_id, hire_dateFROM employeesORDER BY hire_date DESC ;1SELECT employee_id, last_name, salary*12 annsalFROM employeesORDER BY annsal ;2SELECT last_name, department_id, salaryFROM

10、employeesORDER BY department_id, salary DESC;3Substitution Variables. salary = ? department_id = ? . last_name = ? .I want to query different values.Substitution VariablesUse iSQL*Plus substitution variables to: Temporarily store values with single-ampersand (&) and double-ampersand (&) substitution

11、Use substitution variables to supplement the following:WHERE conditionsORDER BY clausesColumn expressionsTable namesEntire SELECT statementsSELECT employee_id, last_name, salary, department_idFROM employeesWHERE employee_id = &employee_num ;Using the & Substitution VariableUse a variable prefixed wi

12、th an ampersand (&) to prompt the user for a value:Using the & Substitution Variable10112SELECT last_name, department_id, salary*12FROM employeesWHERE job_id = &job_title ;Character and Date Values with Substitution VariablesUse single quotation marks for date and character values:Specifying Column

13、Names, Expressions, and TextSELECT employee_id, last_name, job_id,&column_nameFROM employeesWHERE &conditionORDER BY &order_column ;salarysalary 15000last_nameSELECT employee_id, last_name, job_id, &column_nameFROM employeesORDER BY &column_name ;Using the & Substitution VariableUse the double amper

14、sand (&) if you want to reuse the variable value without prompting the user each time:Using the iSQL*Plus DEFINE CommandUse the iSQL*Plus DEFINE command to create and assign a value to a variable.Use the iSQL*Plus UNDEFINE command to remove a variable. DEFINE employee_num = 200SELECT employee_id, la

15、st_name, salary, department_idFROM employeesWHERE employee_id = &employee_num ;UNDEFINE employee_numold 3: WHERE employee_id = &employee_numnew 3: WHERE employee_id = 200SET VERIFY ONSELECT employee_id, last_name, salary, department_idFROM employeesWHERE employee_id = &employee_num;Using the VERIFY

16、CommandUse the VERIFY command to toggle the display of the substitution variable, both before and after iSQL*Plus replaces substitution variables with values:SELECT *|DISTINCT column|expression alias,.FROM tableWHERE condition(s)ORDER BY column, expr, alias ASC|DESC ;SummaryIn this lesson, you shoul

17、d have learned how to: Use the WHERE clause to restrict rows of output:Use the comparison conditionsUse the BETWEEN, IN, LIKE, and NULL conditionsApply the logical AND, OR, and NOT operatorsUse the ORDER BY clause to sort rows of output:Use ampersand substitution in iSQL*Plus to restrict and sort output at run time Practice 2: Overvie

溫馨提示

  • 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)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論