1

私の質問は、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
4

1 に答える 1

1

ANSI SQL に相当するのは、再帰的な共通テーブル式です。

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

recordstatus = 1条件を再帰開始にも適用​​したい場合、私は100%ではありません。


Oracle はここで標準に準拠していないため、recursiveキーワードを使用することはできません。

したがって、上記のクエリから削除 する必要がありrecursiveます (SQL Server の場合も同様です)。

再帰的な共通テーブル式 (Oracle では「サブクエリ ファクタリング」と呼ばれる) の詳細については、次のマニュアルを参照してください。

https://docs.oracle.com/database/121/SQLRF/statements_10002.htm#SQLRF55268

于 2015-11-09T08:08:19.020 に答える