Oracle中Start with...Connect By理解及用法
oracle中connect by prior实现递归查询
收集的几条在oracle中通过connect by prior来实现递归查询
Start with...Connect By子句递归查询一般用于一个表维护树形结构的应用。
创建示例表:
CREATE TABLE TBL_TEST
(
ID NUMBER,
NAME VARCHAR2(100 BYTE),
PID NUMBER DEFAULT 0
);
插入测试数据:
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('1','10','0');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('2','11','1');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('3','20','0');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('4','12','1');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('5','121','2');
从Root往树末梢递归
select * from TBL_TEST
start with id=1
connect by prior id = pid
从末梢往树ROOT递归
select * from TBL_TEST
start with id=5
connect by prior pid = id
===============================================================================================================
有一张表 t
字段:
parent
child
两个字段的关系是父子关系
写一个sql语句,查询出指定父下面的所有的子
比如
a b
a c
a e
b b1
b b2
c c1
e e1
e e3
d d1
指定parent=a,选出
a b
a c
a e
b b1
b b2
c c1
e e1
e e3
&
相关文档:
for example:
15:18:59 SQL> create table t1 (a int, b int);
表已创建。
已用时间: 00: 00: 00.15
......
方法一,使用SQL*Loader
这个是用的较多的方法,前提必须oracle数据中目的表已经存在。
大体步骤如下:
1 将excle文件另存为一个新文件比如文件名为text.txt,文件类型选文本文件(制表符分隔),这里选择类型为csv(逗号分隔)也行,但是在写后面的control. ......
declare
begin
--SQL语句
--直接写的SQL语句(DML/TCL)
--间接写execute immediate <DDL/DCL命令字符串>
--select 语句
<1>必须带有into子句
&n ......
为了确定表空间中包含那些内容,运行:
select owner,segment_name,segment_type
from dba_segments
where tablespace_name='<name of tablespace>'
查询表空间包含多少数据文件。
select file_name, tablespace_name
from dba_data_files
where tablespace_name ='<name of t ......