上一篇:Oracle入門學習二
學習視頻:https://www.bilibili.com/video/BV1tJ411r7EC?p=26
字串函式:length、upper、lower、initcap、 concat、instr、replace,
-- dual 常量表,沒什么意義,就語法規則 -- 獲取字串長度 select length('我是誰?') from dual; select length('abcd') from dual; -- 全部變成大寫 select upper('abcdDDDFFF') from dual; -- 全部變成小寫 select lower('DDAFAFA') from dual; -- 首字母大寫化,后面的也會變成小寫 select initcap('abcdDDD') from dual; -- 從第一個字符開始截取三個字符 select substr('123456789',1,3) from dual; -- 從第三個字符開始截取三個字符 select substr('123456789',3,3) from dual; --字串連接函式 select concat('ab','dc') from dual; --替換函式 select replace('我恨你','恨','愛') from dual; --查找字串出現的首位置 select instr('java','va') from dual;
數字函式:round、trunc,
--四舍五入的取小數位 select round(3.14159,3) from dual; select round(3.14159,2) from dual; --截取小數位,但沒有四舍五入 select trunc(3.14159,3) from dual;
轉換函式:to_char、to_date、to_number
--數字轉字串 --L指本地貨幣 --$指美元 select to_char(5006,'L9999.99') from dual; select to_char(5006,'$9999.00') from dual; select to_char(5006.989,'9999.00') from dual; --字串轉日期 select to_date('2019-05-12','yyyy-mm-dd') from dual; select to_date('2019/05/12','yyyy/mm/dd') from dual; select to_date('2019/05/12 12:23:23','yyyy/mm/dd hh:mi:ss') from dual; --字串轉數字 select to_number('500')+800 from dual;
plsql基本語法熟悉之后,可以配置一下快捷鍵提高效率:https://jingyan.baidu.com/article/215817f7e1efbb1eda1423ef.html
聚合函式:處理多個資料的函式,常見的有max、min、count、sum、avg,
--列有空也不影響 select max(salary) from staff; select min(salary) from staff; select max(bonus) from staff; select sum(bonus) from staff; select avg(bonus) from staff; --count(某列),當該列值不為空才列入計算 select count(bonus) from staff; --總行數 select count(*) from staff;
分組函式:group by,根據一列或多列分組,使用聚合函式同級該組的資料,
where用來篩選from字句產生的行,group by用來分組where字句之后的資料,having用來過濾分組之后的資料,
--單列分組 select name,count(*) from staff group by name; --多列分組 select department,salary,count(*) from staff group by department,salary order by department desc;
--對分組之后的資料,再次進行條件過濾,使用having關鍵字而非where select department,salary,count(*) from staff group by department,salary having count(*)<8 order by department desc ;
--對分組之后的資料,再次進行條件過濾,使用having關鍵字而非where select department,salary,count(*) from staff where salary>40000 group by department,salary having count(*)<8 order by department desc ;
子查詢:查詢套查詢,執行順序先子后父,
select * from student where born_date > (select born_date from student where student_name = 'bibi')
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/4098.html
標籤:Oracle
