ORACLE資料庫學習總結

2021-12-25 12:32:33 字數 5190 閱讀 9687

資料庫學習總結-marlon

目錄一、 oracle_簡介 1

二、 oracle_簡單查詢 2

三、 oracle標量函式和算數運算 5

四、 oracle_多表查詢 9

五、 oracle_列函式和分組 10

六、 oracle_子查詢 12

七、 oracle_表的更新操作 13

八、 oracle_表與檢視的管理 14

◆ oralce資料庫發展

oracle 8

oracle 8i:i表示internet,標識著oracle公司正式進軍網際網路。

oracle9i

oracle10g:g表示grid,即網路技術。

oracle11g

◆ oracle體系結構一

物理結構:

檔案系統

控制檔案

資料檔案

日誌檔案

引數檔案(不是資料庫的組成成分)

◆ oracel體系結構三

邏輯結構:

block 快

extent 盤區

segment 段

tablespace 表空間

datafile 資料檔案

sql * plus下的常用命令

◆ 連線到sql*plus

sqlplus user/password[as sysdaba|sysoper]

sqlplus/nolog

◆ 啟動資料庫

startup mount 啟動例項,開啟控制檔案,但不開啟資料檔案

startup nomount 只啟動例項

◆ 關閉資料庫

shutdown immediate

◆ 迫使每個使用者執行為當前的sql語句,立即斷開連線

shutdown transactional

◆ 迫使使用者執行完當前事務時,斷開連線

shutdown abort

強制關閉資料庫

◆ 常用sql命令

show user:檢視當前連線的使用者

connect scott/tiger: 採用scott的使用者名稱/tiger的密碼連線資料庫

desc table_name:檢視tablename表結構

quit|exit:退出

disconnect:斷開連線

clear screen:清屏,相當於windows下的cls命令

select * from tab:列出當前使用者下的所有表

@pata 執行pata制定的指令碼檔案

◆ oracle常用基本資料型別

varchar2/varchar:變成字串

char:定長字串

integer:整型

number(m,n):數字型

smallint:短整型

float:浮點數

decimal:十進位制數字(小數)

date:日期型

sql結構化查詢語言(structured query language)

◆ sql分類

1. 資料定義語言(data definition language,ddl):create、alter、drop。

create table 表名; alter table add 新列名資料型別; drop table 表名;

2. 資料操縱語言(data manipulation language,dml):insert、update、delete、select。

insert into 表名(欄位1,欄位2…) values(值1,值2…);

update student set sage=22 where sno='200215';(將學生200215的年齡改為22歲)

select distinct job from emp;去除重複行

3. 資料控制語言(data control language,dcl):commit work、rollback work。

◆ 查詢雇員的所有資訊

select * from emp;

*表示所有列

◆ 查詢語句的格式

select *|列名 from 表名

◆ 查詢雇員的編號,姓名,工資

select * from empno,ename,sal from emp;

◆ 查詢所有職位

select job from emp;

select distinct job from emp;

distinct: 有區別的(去除重複行)

◆ 查詢工資大於1500的雇員資訊,列出編號,使用者名稱,工資

select empno,ename,sal from emp where sal>1500;

◆ 帶有where條件查詢語句的基本格式

select *|列名 from 表名 where 條件;

◆ 比較運算子

大於:>

小於:<

等於:=

大於等於:>=

小於等於:<=

不等於:!=或者<>

◆ 限定查詢 is null 和 is not null 的使用

查詢每月可以得到獎金的雇員

select empno,ename,comm from emp where comm is not null;

select empno,ename,comm from emp where comm is not null and comm>0;

查詢誰沒有獎金

select empno,ename from emp where comm is null;

◆ 限定查詢 and 的使用

查詢工資大於1500,並且可以領取獎金的雇員

sql> select empno,ename,sal,comm from emp where comm is not null and sal>1500;

◆ 限定查詢 or 的使用

查詢工資大於1500和可以領取獎金的雇員

select empno,ename,sal,comm from emp where sal>1500 or comm is not null;

查詢沒有獎金的雇員

select empno,ename,comm from emp where comm=0 or comm is null;

◆ 限定查詢使用not對條件整體取反

查詢工資不大於1500並且不能領取獎金的雇員

select empno,ename,sal,comm from emp where sal<=1500 and (comm is null or comm=0);

select empno,ename,sal,comm from emp where not(sal>1500 or comm is not null);

◆ 限定查詢 between...and...的使用

查詢基本工資大於等於1500並且小於等於3000的雇員

select empno,ename,sal from emp where sal>=1500 and sal<=3000;

select empno,ename,sal from emp where sal between 1500 and 3000;

查詢2023年僱傭的所有員工

select empno,ename,hiredate from emp where hiredate between'1-1月 1981' and '31-12月 1981';

注:日期格式日-月年,要匹配上

◆ 限定查詢字串的比較

查詢姓名是'smith'員工的所有資訊

select * from emp where ename='smith';

select * from emp where ename='smith';

注:列值區分大小寫

◆ 限定查詢 in的使用

查詢出編號7369,7499,7521的雇員的具體資訊

select * from emp where empno=7369 or empno=7499 or empno=7521;

select * from emp where empno in(7369,7499,7521);

◆ 限定查詢 not in的使用

查詢出雇員編號不是369,7499,7521的雇員的具體資訊

select * from emp where empno not in(7369,7499,7521);

◆ 限定查詢 like的使用

查詢雇員的名字第二個字元是m的雇員資訊

select * from emp where ename like'_m%';

注:_匹配乙個字元,%匹配0個多個字母(字首或字尾的代表)

查詢2023年入職的所有雇員的資訊

select * from emp where hiredate like'%82';

查詢工資中包含5的雇員資訊

select * from emp sal where like'%5%';

◆ 對結果排序-oracle by

查詢員工工資大於1500員工的資訊,按工資排序

select * from emp where sal>1500 order by sal;

查詢工資大於1500員工的資訊,按工資降序,按僱傭日期公升序排序

select * from emp where sal>1500 order by sal desc,hiredate asc;

注:asc公升序,desc降序,預設asc。

ascending ['sendi]上公升的,降序排列(descend [di'send] 的縮寫);

字元函式的使用

◆ 轉換為大寫字母

select upper('smith') from dual;

注:dual是公共表。upper ['?p?] 上面的,上部的

◆ 轉換為小寫字母

select lower('smith') from dual;

注:lower 放下

◆ 每個單詞的字母變成大寫,其餘字母小寫

select initcap('hello world') from dual

◆ 串連線(concat):可以使用"||"進行串連線

select concat('hello','world') from dual;

select 'hello'||'world' from dual;

Oracle資料庫Spfile學習總結

建立spfile 預設的,oracle使用pfile啟動資料庫,spfile必須由pfile建立,新建立的spfile在下一次啟動資料庫時生效,create spfile需要sysdba或者sysoper的許可權 create spfile spfilename from pfile pfilena...

Oracle資料庫知識總結

ad1.執行乙個sql指令碼檔案 sql start file name sql file name 我們可以將多條sql語句儲存在乙個文字檔案中,這樣當要執行這個檔案中的所有的sql語句時,用上面的任一命令即可,這類似於dos中的批處理。4.將顯示的內容輸出到指定檔案 sql spool file...

oracle資料庫入門

很多剛剛接觸oracle資料庫的初學者總是感覺oracle很難學,無從下手,漸漸的感覺對oracle很排斥,有的朋友找了本oracle是書也是一點也看不懂,或者看了前面幾章,還是不知道怎麼用。其實,從筆者的親身經歷來說,oracle入門很簡單,使用oracle的基本功能也是一件非常簡單的事情。但是想...