oracle递归、合并、遍历查询实例
2016-11-10 09:51
513 查看
<select id="query_top_structure_bySectionId" resultMap="BaseResultMap">
select distinct *
from FP_00000021(where--也可以有where子句作为约束条件)
start with SPARE_PARTS_SN in
<foreach collection="sectionIds" item="sectionId" index="index"
open="(" close=")" separator=",">
#{sectionId} (此处传进一个以逗号为分割符的字符串,分割出来的元素放到集合sections中进行遍历,作为SPARE_PARTS_SN的值)
</foreach>
connect by prior SPARE_PARTS_SN = PARENT_SN
UNION
select distinct *
from FP_00000021
start with SPARE_PARTS_SN in
<foreach collection="sectionIds" item="sectionId" index="index"
open="(" close=")" separator=",">
#{sectionId}
</foreach>
connect by prior PARENT_SN = SPARE_PARTS_SN
</select>
列出所有在中国和美国的不同的雇员名:
SELECT E_Name FROM Employees_China
UNION
SELECT E_Name FROM Employees_USA
注释:这个命令无法列出在中国和美国的所有雇员。在上面的例子中,我们有两个名字相同的雇员,他们当中只有一个人被列出来了。UNION 命令只会选取不同的值。
UNION ALL
UNION ALL 命令和 UNION 命令几乎是等效的,不过 UNION ALL 命令会列出所有的值。
SQL Statement 1 UNION ALL SQL Statement 2
递归删除:
<delete id="deleteClassifyById" parameterType="java.lang.Short" >
delete from APP_PKG_CLASSIFY t1 where id in
( select id from APP_PKG_CLASSIFY t start with t.ID = #{id,jdbcType=DECIMAL} connect by prior t.ID = t.PARENT_ID)
</delete>
select distinct *
from FP_00000021(where--也可以有where子句作为约束条件)
start with SPARE_PARTS_SN in
<foreach collection="sectionIds" item="sectionId" index="index"
open="(" close=")" separator=",">
#{sectionId} (此处传进一个以逗号为分割符的字符串,分割出来的元素放到集合sections中进行遍历,作为SPARE_PARTS_SN的值)
</foreach>
connect by prior SPARE_PARTS_SN = PARENT_SN
UNION
select distinct *
from FP_00000021
start with SPARE_PARTS_SN in
<foreach collection="sectionIds" item="sectionId" index="index"
open="(" close=")" separator=",">
#{sectionId}
</foreach>
connect by prior PARENT_SN = SPARE_PARTS_SN
</select>
UNION 命令:合并两个或多个select的结果集
列出所有在中国和美国的不同的雇员名:SELECT E_Name FROM Employees_China
UNION
SELECT E_Name FROM Employees_USA
结果
E_Name |
---|
Zhang, Hua |
Wang, Wei |
Carter, Thomas |
Yang, Ming |
Adams, John |
Bush, George |
Gates, Bill |
UNION ALL
UNION ALL 命令和 UNION 命令几乎是等效的,不过 UNION ALL 命令会列出所有的值。
SQL Statement 1 UNION ALL SQL Statement 2
递归删除:
<delete id="deleteClassifyById" parameterType="java.lang.Short" >
delete from APP_PKG_CLASSIFY t1 where id in
( select id from APP_PKG_CLASSIFY t start with t.ID = #{id,jdbcType=DECIMAL} connect by prior t.ID = t.PARENT_ID)
</delete>
相关文章推荐
- Oracle 循环递归遍历树结构查询
- oracle start with实现递归查询实例
- (oracle学习笔记)游标实例:通过游标遍历合并数据
- oracle 多个查询语句结果合并
- oracle多表查询实例
- Oracle PL/SQL之递归查询 - CONNECT BY PRIOR
- ORACLE中的合并查询
- Oracle使用SQL语句进行递归查询
- Oracle之SQL基础--合并查询
- ORACLE-合并查询结果
- Oracle PL/SQL之递归查询 - CONNECT BY PRIOR
- 在ORACLE、MSSQL、MYSQL中树结构表递归查询的实现方法
- 树结构表递归查询在ORACLE和MSSQL中的实现方法 [续]
- [转]树结构表递归查询在ORACLE和MSSQL中的实现方法
- oracle查询实例
- oracle 插入、合并、查询、聚合操作
- Oracle中联合查询的实例使用
- Asp.Net递归遍历页面控件实例
- Oracle 递归树型查询(父子互逆查询)
- 二叉查询树三种遍历的非递归写法 [No. 78]