上一篇:Oracle入門學習一
學習視頻:https://www.bilibili.com/video/BV1tJ411r7EC?p=15
算術運算子:+ - * /
邏輯運算子:and or not
比較運算子:“=”、“<”、“>”、“<=”、“>=”、“<>”、“!=”,注意“=”是等于的意思而非賦值,最后兩種都表示不等于,
查找列:
-- 給列起別名,如果列名有空格,則要用雙引號包住 select name 名字,salary*15 "年 薪" from staff where name='張三'; --列的值如果要連接起來,使用|| select name||'-'||salary*15 "員工年薪" from staff where name='張三'; --常量列 select salary,'李子維' "姓名" from staff;View Code
null運算:運算的時候如果有空值參與永遠回傳空,為避免此情況可以借助nvl(param1,param2)函式,param1為空則回傳值為param2,否則param1,
select salary+nvl(bonus,0) all_salary from staff;
排重:無論多列還是單列,只需要在列的最前面加“distinct”關鍵字就可以實作排重,多列排重則是看整個組合是否重復,而非其中一列是否重復,
select distinct salary,name from staff;
where:條件篩選,可以加極限條件例如1=1永遠為真,1!=1永遠為假,字串對比是區分大小寫的,
-- 判空要用 is null select salary,name from staff where salary>80000 or bonus is null;
-- 永真條件 select salary,name from staff where 1=1; -- 永假條件 select salary,name from staff where 1!=1;View Code
-- 字串比較嚴格區分大小寫,且用單引號括住 select salary,name from staff where name='Popo';View Code
模糊查詢之Like:通配符“_”表示任意一個字符,通配符“%”任意長度的字串,使用“like”進行模糊查詢經常用到這兩個通配符,
select salary,name from staff where name like '張%'; select salary,name from staff where name like '張_';
select salary,name from staff where name like '%o_';
模糊查詢之between...and...:等價于 “ 值a >= 值b and 值a <= 值c”,切記包含等于,如果需要不在這個范圍內的資料,只需在between前加個not關鍵字,
select salary,name from staff where salary between 80000 and 90000; select salary,name from staff where salary>=80000 and salary<=90000;
select salary,name from staff where not salary between 80000 and 90000;
模糊查詢之in:表示在某個范圍內,但這個范圍內的值都可以精確的表示,in(4,5,6)表示欄位在4或5或6都可以,不在這個范圍則在not in(......),
select salary,name from staff where salary in (40000,80000); select salary,name from staff where salary not in (40000,80000);
判null:用“is null”而非=null,而不空使用“is not null”,
-- 判斷用is null,非空用 is not null select salary,name from staff where bonus is null; select salary,name from staff where bonus is not null;
order by 排序:排序陳述句永遠放末尾,默認是 asc 升序(小->大),desc為降序(大->小),多列排序也只需寫一次order by,例如“order by 列1 desc,order by 列2 asc,列3 desc”,
select salary,name from staff order by salary; select salary,name from staff order by salary asc; select salary,name from staff order by salary desc;
-- 不寫降序升序,默認升序 select salary,name from staff order by salary ,name ; select salary,name from staff order by salary desc,name desc;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/4097.html
標籤:Oracle
