• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

oracle学习笔记(二)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

一、多行函数又称组合函数(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 top 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','插入')

五,事务: 隐式、显式的事务

commit提交事务
rollback 回滚事务
locking锁
对并发性系统自动加锁,事务提交后、或回滚后自动解锁。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
SQL查询效率注意事项小结发布时间:2022-02-08
下一篇:
mysql向mariadb平滑过渡的步骤详解发布时间:2022-02-08
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap