版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、2022/7/111第4章 用SQL語言訪問數(shù)據(jù)庫SQL語言的概念SQL語句表達(dá)式的建立事務(wù)概念事務(wù)處理ORACLE9i教程本次課程內(nèi)容: 4.1 SQL語言的概念4.2 通過查詢檢索數(shù)據(jù) Oracle的SQL介紹 1. SQL簡介 早期的數(shù)據(jù)庫管理系統(tǒng)常常為不同范疇的任務(wù)使用一個獨立的語言,而SQL將這些任務(wù)全部統(tǒng)一在單個語言下了。 SQL成了關(guān)系數(shù)據(jù)庫事實上工業(yè)標(biāo)準(zhǔn)。 SQL的特點:數(shù)據(jù)存儲于表給定條件即可查詢交互性好命令類型:數(shù)據(jù)定義語言(DDL)數(shù)據(jù)控制語言(DCL)數(shù)據(jù)操縱語言(DML)2.SQL環(huán)境交互式聯(lián)機使用嵌入式SQL Plus是Oracle系統(tǒng)的支持工具之一,利用它可以完成
2、數(shù)據(jù)的建立、存取、數(shù)據(jù)的操縱、查詢等。操作命令:P74顯示表結(jié)構(gòu)緩沖區(qū)操作文件操作4. SQL命令集(1)查詢命令SELECT 這是用得最普遍的命令,它是SQL的最主要、最核心的功能。查詢的意思是用它來從數(shù)據(jù)庫檢索數(shù)據(jù)查詢數(shù)據(jù)庫 SELECT子句一個SELECT命令通??梢苑纸鉃槿齻€部分: 查找什么數(shù)據(jù)?從哪里查找?查找條件是什么?故常用以下子句來表達(dá)from p1,p2pnwhere group by having order by 條件表達(dá)可以用關(guān)系運算、邏輯運算和SQL運算符。SELECT命令的常用形式如下: select 列1,列2列N from 表1,表N 【where 條件】 【o
3、rder by 列1asc|desc列2asc|desc】;Where子句的比較運算符:,, , , =Where子句的比較運算符:AND, OR, NOT, IN, NOT IN, EXISTSdesc scott.emp;desc scott.dept;顯示表結(jié)構(gòu):顯示全部/部分字段:select * from scott.emp;select empno,ename,job from scott.empselect distinct job from scott.emp簡單條件查詢:select empno,ename,job from scott.emp where job=MANAG
4、ERselect empno,ename,sal from scott.emp where sal=CLERK and sal=CLERK or sal=2000select empno,ename,job from scott.emp where not job=CLERK排序查詢:select empno,ename,job from scott.emp where job=CLERK order by job asc,sal descselect empno,ename,job,sal from scott.emp group by job,empno,ename,sal having
5、sal=2000select empno,ename,job,sal from scott.emp where sal=(select sal from scott.emp where ename=WARD);簡單嵌套查詢:select emp.empno,emp.ename,emp.job,emp.sal from scott.empwhere sal in (select sal from scott.emp where ename=WARD);帶in的嵌套查詢:select emp.empno,emp.ename,emp.job,emp.sal from scott.empwhere s
6、al any(select sal from scott.emp where job=MANAGER);帶any的嵌套查詢:select sal from scott.emp where job=MANAGERselect emp.empno,emp.ename,emp.job,emp.sal from scott.empwhere sal 2975 or sal2850 or sal2450;select emp.empno,emp.ename,emp.job,emp.sal from scott.empwhere sal =some(select sal from scott.emp wh
7、ere job=MANAGER);帶some的嵌套查詢:select sal from scott.emp where job=MANAGERselect emp.empno,emp.ename,emp.job,emp.sal from scott.empwhere sal =2975 or sal=2850 or sal=2450;select emp.empno,emp.ename,emp.job,emp.sal from scott.empwhere sal all(select sal from scott.emp where job=MANAGER);帶all的嵌套查詢:select
8、 sal from scott.emp where job=MANAGERselect emp.empno,emp.ename,emp.job,emp.sal from scott.empwhere sal 2975 and sal2850 and sal2450;select emp.empno,emp.ename,emp.job,emp.sal from scott.emp,scott.deptwhere exists(select * from scott.emp where scott.emp.deptno=scott.dept.deptno);帶exists的嵌套查詢:(select
9、 deptno from scott.emp)union(select deptno from scott.dept);并操作的嵌套查詢:(select deptno from scott.emp)intersect(select deptno from scott.dept);交操作的嵌套查詢:(select deptno from scott.dept)minus(select deptno from scott.emp);差操作的嵌套查詢:select mgr, mgr/100,ceil(mgr/100) from scott.emp;Ceil函數(shù):select mgr, mgr/100
10、,floor(mgr/100) from scott.emp;floor函數(shù):select mgr, mod(mgr,1000), mod(mgr,100), mod(mgr,10) from scott.emp;mod函數(shù):select mgr, power(mgr,2),power(mgr,3) from scott.emp;power函數(shù):select mgr, round(mgr/100,2),round(mgr/1000,2) from scott.emp;round函數(shù):select mgr, mgr-7800,sign(mgr-7800) from scott.emp;sign函
11、數(shù):select avg(mgr) 平均薪水 from scott.emp;avg函數(shù):select count(*) 記錄總數(shù) from scott.emp;count函數(shù):select count(distinct job ) 工作類別總數(shù) from scott.emp;select min(sal) 最少薪水 from scott.emp;min函數(shù):select max(sal) 最高薪水 from scott.emp;max函數(shù):select sum(sal) 薪水總和 from scott.emp;sum函數(shù):小結(jié)本次課程主要介紹了結(jié)構(gòu)化查詢語言的概念,主要功能和基本應(yīng)用方法,相應(yīng)的開發(fā)工具SQL Plus及表的操作1、創(chuàng)建用戶的SQL語句是_Create user_,更
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2026浙江衢州職業(yè)技術(shù)學(xué)院高層次緊缺人才招聘32人筆試備考試題及答案解析
- 2026河南周口市川匯區(qū)政府專職消防員招聘18人筆試參考題庫及答案解析
- 2026一季度重慶市屬事業(yè)單位公開招聘242人筆試參考題庫及答案解析
- 2026湖南懷化市溆浦縣社會保險服務(wù)中心公益性崗位招聘考試備考試題及答案解析
- 2026新疆和瑞集團博樂大巴扎項目招聘1人筆試備考題庫及答案解析
- 2026中國醫(yī)學(xué)科學(xué)院藥物研究所招聘23人筆試模擬試題及答案解析
- 2026年廣豐區(qū)殯葬事業(yè)服務(wù)中心勞務(wù)派遣招聘筆試模擬試題及答案解析
- 2026年數(shù)據(jù)挖掘?qū)崙?zhàn)案例培訓(xùn)
- 2026重慶市屬事業(yè)單位第一季度考核招聘高層次和緊缺人才310人筆試備考試題及答案解析
- 2026年工程地質(zhì)鉆探技術(shù)的質(zhì)量控制方法
- 蒙古駕駛證考試題目及答案
- 頭發(fā)白轉(zhuǎn)黑課件
- 醫(yī)院藥劑科窗口服務(wù)規(guī)范化培訓(xùn)
- 家紡產(chǎn)品綠色生命周期管理
- 消化內(nèi)鏡治療進修匯報
- 2025-2030塞爾維亞電力行業(yè)市場現(xiàn)狀供需分析及重點企業(yè)投資評估規(guī)劃分析研究報告
- 設(shè)備日常點檢管理制度
- QGDW11059.2-2018氣體絕緣金屬封閉開關(guān)設(shè)備局部放電帶電測試技術(shù)現(xiàn)場應(yīng)用導(dǎo)則第2部分特高頻法
- (高清版)DB62∕T 25-3128-2017 定型臺架綁扎預(yù)制箱梁鋼筋骨架施工規(guī)程
- 電梯更換配件勞務(wù)合同(2篇)
- 冀人版四年級科學(xué)上冊復(fù)習(xí)資料(分課)
評論
0/150
提交評論