0

我有这样的桌子

表-A

Conversion_logic       Output_param

func(a,b)               c

func(d)                 e

func(c)                 d

func(e)                 f

这里的行描述了func(a,b)给了我“c”,现在这个“c”被应用为func(c)并给了我“d”,现在这个“d”被应用为func(d)并给了我“e”,现在这个“e”被应用为 func(e) 这给了我“f”

所以我想要这样的输出

1) That row should be the first row whose output has no dependency.
2) From there it should follow parent child relation

Conversion_logic       Output_param
func(e)                f
func(d)                e
func(c)                d
func(a,b)              c
4

2 回答 2

2

您可以使用分层查询。

SELECT     table_name.*
  FROM table_name
CONNECT BY PRIOR conversion_logic = 'func(' || output_param || ')'
START WITH conversion_logic = 'func(e)';

更新:

SELECT     table_name.*
  FROM table_name
CONNECT BY PRIOR conversion_logic = 'func(' || ooutput_param || ')'
START WITH ooutput_param =
          (SELECT a.ooutput_param
             FROM table_name a
            WHERE 'func(' || a.ooutput_param || ')' NOT IN (
                                                 SELECT b.conversion_logic
                                                   FROM table_name b));

不确定此查询的性能。也许有更好和更有效的。

于 2013-05-08T05:15:27.137 回答
0

尝试

SELECT t1.*
  FROM taba t1
  LEFT OUTER JOIN taba t2 ON instr(replace(t1.Conversion_logic, 'func'), t2.Output_param) > 0
START WITH t2.Conversion_logic IS NULL
CONNECT BY instr(replace(t1.Conversion_logic, 'func'), PRIOR t1.Output_param) > 0
ORDER BY LEVEL DESC

这是一个 sqlfiddle 演示

于 2013-05-08T07:19:51.813 回答