oracle表的crud(增删改查)单表
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle表的crud(增删改查)单表相关的知识,希望对你有一定的参考价值。
参考技术A 1增加数据:insert into 表名>(属性1,属性2,属性3.,…)values(属性1对应的数据类型的值,属性2对应的数据类型 的 值,属性3对应的数据类型的值,…);
1.删除一行数据:delete from 表名>
where 满足的条件;
例子:delete table student
where snum = ‘2014101’;
2.删除数据从表截断
truncate table (表名);
3.删除表及表的所有数据:
drop table 表名>;
修改表:
update 表名 set 列1=表达式,列2=表达式2
where 列=表达式;
a…对所有列都修改
Update student set sage =sage+1;
b.修改指定的记录
Update sc set Grade=90 where Sno= ‘9521105’;
有关于查找
查询可以分为三种类型:单表查询,多表查询和子查询
这里主要讲的是单表查询
select 属性1,属性2,… from 表名
[where 检索条件]
[ order by 排序依据列]
[group by 分组依据列]
[ having 组提取条件]
1单表查询纵向查询
1.1查全表:select * from 表名
1.2查表的部分: select 查询的内容 from 表名 where 判断的条件
例: select ID,name from 表名 where sex=‘男’;
1.3使用别名:select id as 学号 from 表名;
1.4 计算 select cj~1.1 from 表名
2.单表查询横向查询
2.1 限制行数
select 属性1,属性2, from 表名 rownum<=n; n为查询的行数
2.2 模糊查询:
select 属性1,属性2,… from 表名 where like 属性=‘_()%’;
select 属性1,属性2,… from 表名 where like 属性=‘%()%’;
注释:括号里面是属性里面 某一个实例对象所拥有的;
2.3 消除重复行:
select distinct 属性 from 表名;
2.4 查询空值
select 属性1,属性2… from 表名 where 属性 is null;
2.5取值区间(连续取)
select 属性1,属性2…from 表名 where 属性 between A and B ;
2.6 取值区间(间断取)
select 属性1,属性2…from 表名 where 属性 in (’ ‘,’ ',…) ;
3.排序
order by 排序依据列
desc 降序排序
asc 升序排列
4.函数统计
主要有的统计函数有 max ,min , avg , count ,sum
4.1 使用这些统计函数
select max(cj),min(cj),sum(cj) ,avg(cj) from 表名>;
select max(cj),min(cj),sum(cj) ,avg(cj) from 表名> where 检索条件;
select 属性1,属性2,… max(cj),min(cj),sum(cj) ,avg(cj) from 表名> where 检索条件;
4.2 有关于分组 group by [分组条件]
区分 having 和 where
having 是接在分组后的
where 是接在分组前的
where 后面是不能接统计函数的
举例子:
select 属性1,属性2,… from 表名 group by 属性 having max(属性)>?;
select 属性1,属性2,… from 表名 where 属性>? group by 属性n ;
以上是关于oracle表的crud(增删改查)单表的主要内容,如果未能解决你的问题,请参考以下文章