Oracle常用命令(no 3)

2021-07-03 01:54:17 字數 3495 閱讀 2238

語法

select  *|

from table

[where condition(s)];

示例

示例

select last_name, job_id, department_id

from employees

where last_name = 'whalen';

操作符含義=

等於(不是==)

>

大於>=大於、等於

<

小於<=

小於、等於

<>

不等於(也可以是!=)

示例

select last_name, salary

from employees

where salary <= 3000;

操作符

含義between…and…

在兩個值之間(包含邊界)

in(set)

等於值列表中的乙個

like

模糊查詢

is null空值

between

select last_name, salary

from employees

where salary between 2500

and3500;

in示例

select employee_id, last_name, salary, manager_id

from employees

where manager_id in (100, 101, 201);

like示例1

select  first_name

from employees

where first_name like

's%';

示例2%-可以同時使用

select last_name

from employees

where last_name like

'_o%';

示例3可以使用 escape 識別符號選擇『%』和 『_』 符號

迴避特殊符號的:使用轉義符。例如:將[%]轉為[\%]、[_]轉為[\_],然後再加上[escape 『\』] 即可
select job_id

from jobs

where job_id like 『it\_%『 escape 『\『;

示例

select last_name, manager_id

from employees

where manager_id is

null;

操作符

含義and

邏輯並or

邏輯或not

邏輯否

and

select employee_id, last_name, job_id, salary

from employees

where salary >=10000

and job_id like

'%man%';

or
select employee_id, last_name, job_id, salary

from employees

where salary >= 10000

or job_id like

'%man%';

not
select last_name, job_id

from employees

where job_id

notin ('it_prog', 'st_clerk', 'sa_rep');

優先順序

1算術運算子

2連線符

3比較符

4is[not]null,like,[not]in

5[not]between

6not

7and8or

可以使用括號改變優先順序順序

示例1

select   last_name, job_id, department_id, hire_date

from employees

order

by hire_date ;

示例2降序排序

select   last_name, job_id, department_id, hire_date

from employees

order

by hire_date desc ;

select employee_id, last_name, salary*12 annsal

from employees

order

by annsal;

示例

select last_name, department_id, salary

from employees

order

by department_id, salary desc;

對空值null的處理

優先順序排序

Oracle 常用命令

1 檢視當前所有物件 sql select from tab 2 建乙個和a表結構一樣的空表 sql create table b as select from a where 1 2 sql create table b b1,b2,b3 as select a1,a2,a3 from a whe...

oracle常用命令

create insert delete select 建立使用者必須在sys超級管理員下 連線到超級管理員 conn sys as sysdba sys zhuangyan system zhuangyan scott tiger 查出所有 clerk 辦事員 的姓名及其部門名稱,部門的人數.找出...

oracle 常用命令

建立臨時表空間 02createtemporarytablespace os temp 03tempfile c oracle product 10.2.0 oradata os temp.dbf 04size100m 05autoextendon 06next100m maxsize 1024m ...