oracle數據庫其他常用關鍵字及常用函數


group by---按照某幾列分組

having---分組之后的過濾

like(%, _)---模糊查詢, %表示   select * from emp e where e.empname like '%ccc%'

distinct---去除重復    select distinct e.empname from emp e;

between...and(閉合區間, 即包括前面的數, 也包括后面的數)   select * from emp e where e.id between 5 and 10;

all---表示一個集合中所有的元素      select * from emp e where e.intime>= all(select intime from emp);

any/some---表示一個集合中任意一個元素

 

常用函數

to_char---轉換成字符型數據

vselect to_char (sysdate,'yyyy-mm-dd hh:mi:ss') from dual; 時間是12小時制

select to_char (sysdate,'yyyy-mm-dd pmhh:mi:ss') from dual; 時間前面帶上午下午

select to_char (sysdate,'yyyy-mm-dd pmhh:mi:ss') from dual; 12小時制時間前面不帶0(1:25:25)

select to_char (sysdate,'yyyy-mm-dd hh24:mi:ss') from dual; 24小時制時間

select to_char (sysdate,'yyyy-mm-dd pmhh24:mi:ss') from dual; 24小時制前面顯示上午下午(沒用)

 

to_date---轉換成日期型數據        dual(數據庫內的一些虛擬抽象表)

      select to_date('2017-04-25 13:56:30','yyyy-mm-dd hh24:mi:ss')from dual;

 

分組函數:

mod---取余函數

avg---平均數函數    select avg(e.sal) from emp e;

sum---求和函數(☆任何數字與NULL相加,結果都為NULL!!!)  select sum(e.sal) from emp e;

count---計數函數 (空的不計數,只記有的)   select count(e.comm) from emp e

decode---類似於分支語句的函數    select decode(e.ssex, 0,'女',1,'男','不詳') 性別 from emp e;

substr---分割字符串    select substr('qweasdfqweqwr',2,4) from dual;(從第二個w開始取,取出四個)

max---取最大值函數    select e.deptid, max(e.intime) 每組最大 from emp e group by e.deptid;

select * from emp e where e.intime = (select max(intime)from emp);  (查表里日期最大的)

min---取最小值函數    select min(e.intime) from emp e;

trunc---取整函數(小數點位數全部舍去,沒有四舍五入)  select trunc(12.3) from dual;

ceil---向上取整函數  (取上一位整數,沒有四舍五入)  select ceil(12.3) from dual;

floor---向下取整   (取下一位整數,沒有四舍五入) select floor(12.8) from dual;

nvl---過濾空值函數  select nvl(e.comm,'') from emp e;(兩個參數前面是有就顯示原有的,后面是沒有參數要顯示的內容)

nvl2---過濾空值函數2   select nvl2(e.comm,'有','沒有')  是否空from emp e;(三個參數:查詢源,有參數要顯示的內容,無參數要顯示的內容)

lower---將字母全部改為小寫   select lower ('aBcD') from dual;

upper---改為大寫            select upper ('aBcD') from dual;

concat---連接兩個字符串(只能連接2字符串多了報錯)  select concat('hello','world') from dual;

order by 1,2  

 --select p.id,p.pcode,p.pname from product p order by 1 desc,2,3(數字順序代表select 后面查詢內容優先按誰的順序排列,列表還是按照p.id,p.pcode,p.pname排序)

group by 增強版

語法: select p.toma, p.ptype, sum(p.lastcou) from product p group by rollup(p.toma, p.ptype)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM