Oracle数据库操作基本语法

   

 

 

查询空值

/(

非空

)

的数据

 

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值