oracle学习笔记(二)

2022-05-24 0 732

一、多行函数又称组合函数(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锁
对并发性系统自动加锁,事务提交后、或回滚后自动解锁。

免责声明:
1、本网站所有发布的源码、软件和资料均为收集各大资源网站整理而来;仅限用于学习和研究目的,您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。 不得使用于非法商业用途,不得违反国家法律。否则后果自负!

2、本站信息来自网络,版权争议与本站无关。一切关于该资源商业行为与www.niceym.com无关。
如果您喜欢该程序,请支持正版源码、软件,购买注册,得到更好的正版服务。
如有侵犯你版权的,请邮件与我们联系处理(邮箱:skknet@qq.com),本站将立即改正。

NICE源码网 MsSql oracle学习笔记(二) https://www.niceym.com/60475.html