欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ORACLE知识点学习总结

程序员文章站 2022-11-22 17:04:09
***ORACLE知识点***1 merge into 的使用(merge into修改的效率是update语句的指数倍,当修改 大量数据时可以使用merge into)语法格式:merge into table ausing table b(一般是临时表)on(修改条件,必须保证唯一性)b.classid=‘001’when match then(符合条件时执行,可以是修改或者新增语句 )update set a.classname=b.classnamewhen no......
					***ORACLE知识点***

1 merge into 的使用(merge into修改的效率是update语句的指数倍,当修改 大量数据时可以使用merge into)
语法格式:
merge into table a
using table b(一般是临时表)
on(修改条件,必须保证唯一性)
b.classid=‘001’
when match then
(符合条件时执行,可以是修改或者新增语句 )
update set a.classname=b.classname
when not match then
(不符合条件时执行,可以是修改或者新增语句 )
insert (a.classname) values(b.classname)
2 判断是否为空,不能使用 == 要使用is null 或者 is not null.(null比较特殊)
3 视图的创建和使用
create or replace view v_a as select a.age from a
select * from v_a
4 listagg用法(将分组后的某字段按指定连接符相加后拼接为一个新的字段,为varchar2,最大值为4000)
select a.classid,listagg(a.stuname,’,’) within group(order by a.classid) allStuname from a group by a.classid
5 connect by prior用法 (处理树形数据表的数据)
1) 创建表t1
create table t1(
rootid number(3),
id number(3),
name varchar2(30) )****
2)插入数据
insert into t1(rootid ,id,name) values(‘0’,‘1’,‘a’)
insert into t1(rootid ,id,name) values(‘1’,‘2’,‘a1’)
insert into t1(rootid ,id,name) values(‘1’,‘3’,‘a2’)
insert into t1(rootid ,id,name) values(‘0’,‘4’,‘b’)
insert into t1(rootid ,id,name) values(‘4’,‘5’,‘b1’)
insert into t1(rootid ,id,name) values(‘4’,‘6’,‘b2’)
insert into t1(rootid ,id,name) values(‘2’,‘7’,‘a3’)
insert into t1(rootid ,id,name) values(‘2’,‘8’,‘a4’)
3)查询树形数据
获取完整树形数据
select * from t1 start with t1.rootid=‘0’ connect by prior t1.id= t1.rootid
获取i指定节点(rootid=1)的所有子树(包含本身)
select * from t1 start with t1.rootid=‘1’ connect by prior t1.id =t1.rootid
结果为(‘1’,‘2’,‘a1’),(‘1’,‘3’,‘a2’),(‘2’,‘7’,‘a3’),(‘2’,‘8’,‘a4’)
获取指定节点(rootid=1)的所有父节点(包含本身)
select * from t1 start with rootid=‘1’ connect by prior rootid = id
结果为(‘1’,‘2’,‘a1’),(‘1’,‘3’,‘a2’),(‘0’,‘1’,‘a’)
6 with as的用法(经常使用在复杂查询中,含有多个子查询的时候)
with a as(
select * from a
),
b as(
select * from b
)
select a.id,b.id from a,b

本文地址:https://blog.csdn.net/baibaibaixiaobai/article/details/108996109

相关标签: Oracle