PLSQL-递归SQL的游标

时间:2018-12-06 17:38:47

标签: sql oracle plsql

我有一个递归SQL查询,它看起来像这样:

WITH goes(from_, to_) AS 
 (
  SELECT from_, to_ FROM ways
   UNION ALL
  SELECT ways.from, goes.to_ FROM ways, goes
  WHERE ways.to_ = goes.from_ AND ways.from_ <> goes.to_
 )
 CYCLE from_ SET is_cycle TO 'I' DEFAULT 'N' 
 SELECT  distinct from_, to_ FROM goes order by 1

我想编写一个plsql过程,该过程可以作为游标处理此查询的输出,但是我不知道如何启动它。

能帮我一下吗?谢谢。

1 个答案:

答案 0 :(得分:0)

这取决于您所说的“句柄”。最简单的是隐式的FOR游标:

for rec in 
  (
     with goes as ....... order by 1
  )
loop
   -- enter processing commands here
end loop;