我的问题可能对sql专家没有挑战性。我想将我的sql重写为ansi-sql。如何在Oracle中将sql更改为ansi-sql?
select *
from TEST r
start with r.childid=@CHILDID
connect by prior r.PARENTID=r.childid and r.recordstatus=1
答案 0 :(得分:1)
ANSI SQL等效项将是一个递归公用表表达式:
var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(new {Field1="Value1"});
如果您还想将with recursive tree as (
select *
from test
where childid = .... --<< this is the START WITH part
union all
select child.*
from test child
join tree parent ON child.parentid = parent.childid and child.recordstatus = 1 --<< this is the CONNECT BY part
)
select *
from tree
条件应用于递归开始,我不是100%。
Oracle不符合此处的标准,您不能使用recordstatus = 1
关键字。
因此您需要从上面的查询中删除 recursive
(对于SQL Server也是如此)
有关递归公用表表达式的更多详细信息(在Oracle中称为“子查询因子”)可以在手册中找到:
https://docs.oracle.com/database/121/SQLRF/statements_10002.htm#SQLRF55268