oracle学习笔记(二)
一、多行函数又称组合函数(Group Functions)、聚合函数
1、 Types of Group Functions
avg、count、max、min、stddev、sum、variance
avg 求平均数
select avg(nvl(列1,0)) from 表1
count求行数
在where条件中不允许使用聚合函数,但可以使用having avg(列1)>1000
having所起的作用和where一样
二、子查询Subqueries
查询前10行数据
oracle: select * from 表名 where rownum<=10;
sql: select 10 * from 表名
单行子查询
select * from 表1 where 工资列1>(select avg(工资列1) from 表1)
多行子查询
select * from 表1 where 工资列1 in(select min(工资列1) from 表1 group by 部门列)
三、自定义变量
set verify on/off
show all
help show/set
column lie justify left
四、数据操作语句
1、insert插入语句
向表2里插入数据
oracle:insert into (select 列1,列2 from 表2)values('XXX','XXX');
oracle/sql:insert into(列1,列2)values('XXX','XXX');
从另一个表里复制数据
oracle/sql:insert into 表(列1,列2)select 列1,列2 from 表2
2、update语句
都为: update table set column1='...'[ ,column2='...'] where ...
嵌入子查询的修改
update table set column1=(select column2 form table where columnid=1) where column1='...'
delete删除语句
delete [from] table [where condition]
merge 合并语句
oracle:
merge into 表1 a using 表2 b on (a.id=b.id)
when matched then
update set
a.name=b.name,
a.other=b.other
when not matched then
insert values(b.id,b.name,b.other);
sql:合并insert,update
方法1:
declare @ROWCOUNT int
set @ROWCOUNT=(select count(*) from tb_name where name1='5')
if @ROWCOUNT!=0
update tb_name set name2='55555555' where name1='5'
else
insert into tb_name(name1,name2) values('5','插入')
方法2:
update tb_name set name2='55555555' where name1='6'
if @@ROWCOUNT=0
insert into tb_name(name1,name2) values('6','插入')
五,事务: 隐式、显式的事务
mit提交事务
rollback 回滚事务
locking锁
对并发性系统自动加锁,事务提交后、或回滚后自动解锁。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程