1. 程式人生 > >oracle學習筆記(五) SQL操作符

oracle學習筆記(五) SQL操作符

sel 算術 oracle學習 sca like 通配 union all 比較操作符 sele

SQL操作符

算術操作符:+加,-減,*乘,/除

比較操作符:

  • <,>,=,!=,<>,<=,>=
    常用的判斷,<>和!=相同
  • between $lower_val$ and $hight_val$
    between .. and.. 包括兩端
--查詢20<=age<=21的學生數據
select * from student where age between 20 and 21
  • not between $lower_val$ and $hight_val$
    與上面相反
  • in(值列表), not in(值列表)
--查詢年齡是20或21的學生數據
select * from student where age in (20,21)
  • is null, IS NOT NULL
    是否為空
  • like, not like
    匹配 ( 通配 )操作符:
    • % 匹配任意多個字符;
    • _ 匹配任意單個字符;
    • 可以使用escape ‘$‘指定轉義字符,默認是""
--姓氏為張的學生,張二,張三,張四五都符合條件
select * from student where name like '張%';
--名字含有三的
select * from student where name like '%三%';
--姓氏為張,名字只有兩個字的學生
select * from student where name like '張_';
--名字中包含%號的
select * from student where name like '%\%%' escape '\' ;

邏輯操作符: AND, OR, NOT

與,或

連接操作符: ||

-- 查詢student表中你的num和name列,並把這兩列顯示出來
select num||,||name from student

集合(查詢的結果集)操作符

下一章《高級查詢》再講
a)UNION 聯合,將兩個查詢結果拼起來
b)UNION ALL 聯合所有,多出現重復行
c)INTERSECT 交集
d)MINUS 減集

oracle學習筆記(五) SQL操作符