select * from theTABLE start with parent_ID=0 connect by prior ID=parent_ID

解决方案 »

  1.   

    08:39:20 SQL> select * from t1;        ID  PARENT_ID DESCRIPTION
    ---------- ---------- --------------------
             0          0
             1          2
             2          3
             3          0已用时间:  00: 00: 00.15
    08:39:25 SQL> select id,parent_id,0 orderid from t1 where id=parent_id and paren
    t_id=0 union
    08:39:29   2  select id,parent_id,level orderid from (select * from t1 where id<
    >parent_id) start with parent_id=0 connect by prior id=parent_id order by orderi
    d;        ID  PARENT_ID    ORDERID
    ---------- ---------- ----------
             0          0          0
             3          0          1
             2          3          2
             1          2          3已用时间:  00: 00: 00.00
      

  2.   

    select id,parent_id,rownum orderid from tbname
    start with id=0 connect by prior id=parent_id;
      

  3.   

    to zmgowin(隐者(龙祖宗)) :
    为什么我在SQL Scratchpad中,使用select ID, level order From table时显示错误:末找到预期的Form?
      

  4.   

    SQL Scratchpad 是oracle enterprise manager console中带的SQL查询器。另:为什么在相关oracle中的帮助中的select文档里并没有 start with ... conncet by...这方面的介绍?thanks
      

  5.   

    start with这种语法是oracle提供的专门用于树状查询的
    10:24:33 SQL> help select SELECT
     ------ Use this command to retrieve data from one or more tables, object
     tables, views, object views, or snapshots. SELECT
       [ DISTINCT | ALL ]
       { *
       | { [ schema. ]{ table | view | snapshot } .*
         | expr [ [ AS ] c_alias ] }
       [, { [ schema. ]{ table | view | snapshot } .*
          | expr [ [ AS ] c_alias ] } ] ...
     FROM
       { [ schema. ]
         { table [ PARTITION ( partition_name ) | @dblink ]
         | [ view | snapshot ] [ @dblink ] }
       [ t_alias ]
       | [ THE ] ( subquery )
       [ t_alias ]
       | TABLE ( nested_table_column )
       [ t_alias ] }
       [, { [ schema. ]
            { table [ PARTITION ( partition_name ) | @dblink ]
            | [ view | snapshot ] [ @dblink ] }
          [ t_alias ]
          | [ THE ] ( subquery )
          [ t_alias ]
          | TABLE ( nested_table_column ) } ] ...
       [ WHERE condition ]
       [ [ START WITH condition ] CONNECT BY condition
         | GROUP BY expr [, expr] ...
         [ HAVING CONDITION ] ] ...
       [ { UNION
         | UNION ALL
         | INTERSECT
         | MINUS } SELECT command ]
       [ ORDER BY { expr | position | c_alias } [ ASC | DESC ]
       [, { expr | position | c_alias } [ ASC | DESC ] ] ...
       | FOR UPDATE
         [ OF [ [ schema. ]{ table. | view. } ] column
              [, [ [schema.]{table. | view.} ] column] ...] [NOWAIT] For detailed information on this command, see the Oracle8 Server SQL
     Reference.
      

  6.   

    to zmgowin(隐者(龙祖宗)) :i am wondering whether u have a MSN passport. if so, it will be by great appreciate that i can get ur msn.thx again!
      

  7.   

    问题:我怎么在SQL plus中运行“help select” 没的帮助文件出现
    Oracle9 Server SQL Reference的帮助文件从哪里可以得到?
      

  8.   

    到官方网站去找找
    oracle帮助里面就有
      

  9.   

    to:bzszp(www.bzszp.533.net)
    你用的这个语句执行的效率很低的,请问有什么方法改善吗?