Oracle 條件查詢 模糊查詢

來源:互聯網
上載者:User

標籤:oracle   ora   null   系統時間   comm   擷取   區分大小寫   當前系統時間   大小寫   

樣本:

1)      查詢出工資高於3000的員工資訊

select  *

froms_emp e

where e.salary>3000;

 

2)      查詢出名為Carmen的員工所有資訊

select * from s_emp e

wheree.first_name =‘Carmen‘;

【oracle sql  關鍵字,表名,列名等不區分大小寫, 記錄中的值大小寫敏感】

 

3)      查詢出沒有績效的員工資訊

select * from s_emp e

where  e.commission_pct is not null;

 

4)      查詢出工資在1200-3000 之間的員工的姓名,部門編號與薪資

selecte.first_name,e.dept_id,e.salary

froms_emp e

wheree.salary>=1200 and e.salary<=3000;

 

selecte.first_name , e.dept_id,e.salary

froms_emp e

wheree.salary between 1200 and 3000;

  • like : 模糊查詢

萬用字元 % 與 _

% :表示任意多個字元

_ : 表示任意一個字元

 

1)      查詢出員工姓名中包含字母為‘a‘的員工的資訊

select * from s_emp e

where e.first_name like ‘%a%‘

 

2)      查詢出員工姓名中第一個字母為‘S‘的員工的姓名

select * from s_emp e

wheree.first_namelike‘S%‘

 

3)      查詢出員工姓名中包含‘a‘和‘f‘的員工的資訊

select * from s_emp e

wheree.first_name like ‘%a%‘ and e.first_name like ‘%f%‘;

4)      查詢出員工姓名中倒數第三個字母為‘i‘的員工的資訊       

select * from s_emp e

wheree.first_name like ‘%i__ ‘

 

5)      查詢出在31,41部門的所有員工的姓名,部門編號與職位

selecte.first_name,e.dept_id,e.title from s_emp e

wheree.dept_id = 31 or e.dept_id = 41;

 

selecte.first_name,e.dept_id,e.title from s_emp e

where e.dept_id in (31,41);

 

【in(31,41)相當於:dept_id=31 or dept_id=41】

 

6)      找出既不是銷售,也不是辦事員的員工

select * from s_emp

where title != ‘Sales Representative’and title != ‘Stock Clerk’;

 

select * from s_emp

where title not in(‘Sales Representative’,’Stock Clerk’);

 

【not in(‘Sales Representative’,’Stock Clerk’)相當於】

title != ‘Sales Representative’and title != ‘Stock Clerk’

  • 【dual 表: oracle中虛擬表,保證sql語句完整。】

【獲得 4+30 的值】

select (4+30) from dual;

 

【獲得當前系統時間】

Select sysdate from dual;

 

【 擷取 ‘hello’】

select  ‘hello‘  from dual;

Oracle 條件查詢 模糊查詢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.