查询空值
/(
非空
)
的数据
SQL>select * from
student
where
brithday
is null
(
/not null
)
;
修改(更新)数据
SQL
>
update
student
set
sal=sql/2
where
sex =‟
男
‟
;
更改多项数据
SQL>
update
emp
set
(job,sal,comm)
=
(select
job,sal,comm
from
emp
where
ename='SMITH')
where ename='SCOTT';
删除数据
1.
保存还原点
SQL>savepoint
aa
;
2.
删除数据
【
1
】
SQL>delete from
student
;
//
删除表的数据
【
2
】
SQL>drop table
student
;
//
删除表的结构和数据
【
3
】
SQL>delete from
student
where
xh=‟001‟
;
//
删除一条记录
【
4
】
SQL>truncate table
student
;
//
删除表中的所有记录,
表结构还在,
不写日志,
无法扎找回的记录,速度快
查看表结构
SQL>desc
student
;
查询指定列
SQL>select
sex,xh,xm
from
student
;
如何取消重复
SQL>select distinct
deptno,job
from
student
;
打开显示操作时间的开关
SQL>set timing on;
为表格添加大的数据行(用于测试反应时间)
SQL>insert into
users
(
userid,username,userpss
) select * from
users
;
统计表内有多少条记录
SQL>select count(*) from
users
;
屏蔽列内相同数据
SQL>select distinct
deptno,job
from
emp
;
查询指定列的某个数据相关的数据
SQL
>
select
deptno,job,sal
from
emp
where
ename
=
‟smith
‟;
使用算数表达式
SQL>select
sal*12
from
emp
;
使用类的别名
SQL>select
ename
“
姓名
”
,
sal*12 as “
年收入
”
from
emp
;
处理
null(
空
)
值
SQL>select
sal*13+nvl(comm,0)*13 “
年工资
”
,
ename,comm
from
emp
;
连接字符串(
||
)
SQL
>
select
ename || „is a‟ || job
from
emp
;
Where
子句的使用
【
1
】
SQL>select
ename,sal
from
emp
where
sal>3000
;
//number
的范围确定
【
2
】
SQL>select
ename,hiredate
from
emp
where
hiredate>‟1
-1
月
-
1982‟
;
//
日期格式的范围确定
【
3
】
SQL>select
ename,sal
from
emp
where
sal>=2000
and
sal<=2500
;
//
组合条件
Like
操作符:
‟%‟
、
‟_‟
SQL>select
ename,sal
from
emp
where
ename
like „
S
%‟;
//
第一个字符【名字第一个
字符为
S
的员工的信息(工资)
】
SQL>select
ename,sal
from
emp
where
ename
like „
__O
%‟;
//
其它字符【名字第三
个字符为
O
的员工的信息(工资)
】
批量查询
SQL>select * from
emp
where in(
123,456,789
);
//
查询一个条件的多个情况的批量处理
查询某个数据行的某列为空的数据的相关数据
SQL >select * from
emp
where
mgr
is null;
条件组合查询(与、或)
SQL>select * from
emp
where
(sal>500 or job=‟MANAGER‟)
and
ename
like
„J%‟
;
Order by
排序
【
1
】
SQL>select * from
emp
order by
sal
(
asc
)
;
//
从低到高
[
默认
]
【
2
】
SQL>select * from
emp
order by
sal
desc;
//
从高到低
【
3
】
SQL>select * from
emp
order by
deptno
(asc),
sal
desc;
//
组合排序
【
4
】
SQL>select
ename,sal*12 “
年薪
”
from
emp
order by
“年薪”
(asc);
SQL> select
ename,(sal+nvl(comm,0))*12 as "
年薪
"
from
emp
order by
"
年薪
"
;
资料分组(
max
、
min
、
avg
、
sum
、
count
)
SQL>select
max(sal),min(sal)
from
emp
;
查询空值
/(
非空
)
的数据
SQL>select * from
student
where
brithday
is null
(
/not null
)
;
修改(更新)数据
SQL
>
update
student
set
sal=sql/2
where
sex =‟
男
‟
;
更改多项数据
SQL>
update
emp
set
(job,sal,comm)
=
(select
job,sal,comm
from
emp
where
ename='SMITH')
where ename='SCOTT';
删除数据
1.
保存还原点
SQL>savepoint
aa
;
2.
删除数据
【
1
】
SQL>delete from
student
;
//
删除表的数据
【
2
】
SQL>drop table
student
;
//
删除表的结构和数据
【
3
】
SQL>delete from
student
where
xh=‟001‟
;
//
删除一条记录
【
4
】
SQL>truncate table
student
;
//
删除表中的所有记录,
表结构还在,
不写日志,
无法扎找回的记录,速度快
查看表结构
SQL>desc
student
;
查询指定列
SQL>select
sex,xh,xm
from
student
;
如何取消重复
SQL>select distinct
deptno,job
from
student
;
打开显示操作时间的开关
SQL>set timing on;
为表格添加大的数据行(用于测试反应时间)
SQL>insert into
users
(
userid,username,userpss
) select * from
users
;
统计表内有多少条记录
SQL>select count(*) from
users
;
屏蔽列内相同数据
SQL>select distinct
deptno,job
from
emp
;
查询指定列的某个数据相关的数据
SQL
>
select
deptno,job,sal
from
emp
where
ename
=
‟smith
‟;
使用算数表达式
SQL>select
sal*12
from
emp
;
使用类的别名
SQL>select
ename
“
姓名
”
,
sal*12 as “
年收入
”
from
emp
;
处理
null(
空
)
值
SQL>select
sal*13+nvl(comm,0)*13 “
年工资
”
,
ename,comm
from
emp
;
连接字符串(
||
)
SQL
>
select
ename || „is a‟ || job
from
emp
;
Where
子句的使用
【
1
】
SQL>select
ename,sal
from
emp
where
sal>3000
;
//number
的范围确定
【
2
】
SQL>select
ename,hiredate
from
emp
where
hiredate>‟1
-1
月
-
1982‟
;
//
日期格式的范围确定
【
3
】
SQL>select
ename,sal
from
emp
where
sal>=2000
and
sal<=2500
;
//
组合条件
Like
操作符:
‟%‟
、
‟_‟
SQL>select
ename,sal
from
emp
where
ename
like „
S
%‟;
//
第一个字符【名字第一个
字符为
S
的员工的信息(工资)
】
SQL>select
ename,sal
from
emp
where
ename
like „
__O
%‟;
//
其它字符【名字第三
个字符为
O
的员工的信息(工资)
】
批量查询
SQL>select * from
emp
where in(
123,456,789
);
//
查询一个条件的多个情况的批量处理
查询某个数据行的某列为空的数据的相关数据
SQL >select * from
emp
where
mgr
is null;
条件组合查询(与、或)
SQL>select * from
emp
where
(sal>500 or job=‟MANAGER‟)
and
ename
like
„J%‟
;
Order by
排序
【
1
】
SQL>select * from
emp
order by
sal
(
asc
)
;
//
从低到高
[
默认
]
【
2
】
SQL>select * from
emp
order by
sal
desc;
//
从高到低
【
3
】
SQL>select * from
emp
order by
deptno
(asc),
sal
desc;
//
组合排序
【
4
】
SQL>select
ename,sal*12 “
年薪
”
from
emp
order by
“年薪”
(asc);
SQL> select
ename,(sal+nvl(comm,0))*12 as "
年薪
"
from
emp
order by
"
年薪
"
;
资料分组(
max
、
min
、
avg
、
sum
、
count
)
SQL>select
max(sal),min(sal)
from
emp
;