程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> Orcal數據庫復習筆記

Orcal數據庫復習筆記

編輯:Oracle教程

Orcal數據庫復習筆記


①在sql中不等於使用的是<>

eg:select * from emp where deptno <>10;

①模糊匹配 關鍵字是like _代表一個字符,%代表0個或多個.

eg: select ename from emp where ename like '_A%';
②sql中的轉義字符用 escape 關鍵字後面跟上'使用的字符'(經實驗''中字符可以為任意字符,數字和字母也可以,但必須能能是1個字符)
eg:SELECT * FROM student WHERE sname LIKE '%\%%' ESCAPE '\' ;
SELECT * FROM student WHERE sname LIKE '%$%%' ESCAPE '$' ;

③使用order by排序時 默認是按升序排列 asc 可以不寫,降序是用desc.

使用組合時,是先按使用排序的第一個字段排序,第一個字段順序拍好後,內部的順序再用後面的字段排序規則
eg:select ename,sal,deptno from emp order by deptno asc,ename desc;
上面的例子先按deptno的升序拍好後,在同一個deptno內的數據按ename的降序排列
所以,一定要考慮好排序的主字段是哪個!!!

④ 一個簡單的綜合sql語句

select ename,sal*12 年薪 from emp
where ename not like '_A%' and sal > 800
order by sal desc;

⑤字符函數:substr(字段名,開始的字符位置,截取的字符段長度) 字符串的下標是從1開始的 經實驗起始字段寫0和1結果都是從第一個字符開始的

eg: select substr(ename,0,2 ) from emp;
select substr(ename,1,2 ) from emp;
上面兩句的執行結果是一樣的

⑥數字函數:Ⅰ round(m)四捨五入到整數; round(m,n) n是正數,代表小數的位數 ,n是負數,則是正數的四捨五入

select round(23.456) from dual;//結果23
select round(23.456,2)from dual;//結果23.46
select round(23.456,-1)from dual;//結果 20
select round(123.456,-2)from dual;//結果100
Ⅱ trunc(m,n) 截斷 n是正數時是小數點後保留的位數,是負數時,該位為0;
select trunc(23.456,1)from dual;//結果23.4
select trunc(23.456,-1)from dual;//結果-1

★⑦轉換函數:to_char( 要轉換的數據,格式) 在日期格式轉換中,hh24是24小時制,hh是12小時制 分鐘用mi

eg:select to_char(sysdate ,'yyyy-mm-dd hh24:mi:ss') from dual;輸出結果:2014-09-13 15:13:17
select to_char(sysdate ,'yyyy-mm-dd hh:mi:ss') from dual; 輸出結果:2014-09-13 03:13:17

★⑧聚合函數:sum(),avg(),count(),max(),min()

count(1)和count(*)都是查詢表中總共多少條記錄數.推薦使用count(1)說效率快,自己沒做實驗,
count(字段名) 代表本字段非空的記錄數.
count(distinct 字段名) 去掉重復後本字段的記錄數
eg:select count(1) from emp;//結果 14 說明表中總共14條記錄
select count(*) from emp;//結果 14 說明表中總共14條記錄
select count(comm) from emp;//結果 4 說明comm列非空的是4條記錄
select count(deptno) from emp;//結果14 說明表中deptno非空的記錄數是14條
select count(distinct deptno) from emp;//結果 3 說明表中不重復的detpno記錄是3

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved