GBase 8a
适配迁移
文章
GBase 8a集群with语句包含递归sql改写建议
发表于2025-05-16 17:32:44163次浏览1个评论
问题现象:
with语句包含递归sql改写。
处理方法:
示例1
create table A_ORGAN(id int,name varchar(16),parent int);
insert into A_ORGAN values(1,'南大通用',0);
insert into A_ORGAN values(2,'行销部',1);
insert into A_ORGAN values(3,'专业服务组',2);
insert into A_ORGAN values(4,'售后组',2);
with rpl(id,name,parent) as
(select id, name, parent
from A_ORGAN
where parent =1
union all
select t1.id, t1.name, t1.parent
from rpl t2, A_ORGAN t1
where t2.id = t1.parent)
select * from rpl oracle中执行结果 :
SQL> with rpl(id,name,parent) as
2 (select id, name, parent
3 from A_ORGAN
4 where parent =1
5 union all
6 select t1.id, t1.name, t1.parent
7 from rpl t2, A_ORGAN t1
8 where t2.id = t1.parent)
9 select * from rpl ;
ID NAME PARENT
---------- ---------------- ----------
2 行销部 1
3 专业服务组 2
4 售后组 2在GBase 8a中目前不支持这种复杂的with语句,使用START WITH CONNECT BY改写,由于当前限制只支持复制表,改写如下:
create table A_ORGAN1(id int,name varchar(16),parent int)replicated;
SELECT ID
,NAME
,PARENT
FROM A_ORGAN1 start WITH PARENT = 1
connect BY prior ID = PARENT;
gbase> SELECT ID
-> ,NAME
-> ,PARENT
-> FROM A_ORGAN1 start WITH PARENT = 1
-> connect BY prior ID = PARENT;
+------+-----------------+--------+
| ID | NAME | PARENT |
+------+-----------------+--------+
| 2 | 行销部 | 1 |
| 3 | 专业服务组 | 2 |
| 4 | 售后组 | 2 |
+------+-----------------+--------+
3 rows in set (Elapsed: 00:00:00.00)
热门帖子
- 12025-12-01浏览数:182763
- 22023-05-09浏览数:25057
- 42023-09-25浏览数:18525
- 52020-05-11浏览数:17528