×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

Try this hierarchical query.

Why not try the following SQL query.

SELECT LPAD(\" \", 2*(LEVEL-1))||column1, column2, ...
FROM table_name
WHERE column1 like \"A%\"
START WITH column1 = \"A\"
CONNECT BY prior column1 = substr(column1, 1, length(column1) - 1);

Result like:

column1 column2 ...
------------ ------------
A
AA
AAA
AAB
AB


The \"LEVEL\", \"START WITH\", \"prior\" and \"CONNECT BY\" are the Oracle key words

Note: LPAD(\" \"), \"A%\", \"A\" , the \" should be replaced by DAN1 YIN3 HAO4.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / Can Table be Inheretence? details in contents.
    For example:
    The first table: (id char(5), name varchar2(20))
    The second table: (id char(5), name varchar2(20), age int)
    The first table: (id char(5), name varchar2(20), age int, pc char(6))
    ......

    I may need such tables more than 20.

    if can inheret, I'll not care too much about the table name or type. Otherwise, if I should add one column into every table, that should be a hard work for me.

    tks.
    • There is no inheretence like what you said in Oracle. why you use the tables like that. If you follow the ERD you never get the tables like these.
      • Dear oneway, that is the key. Such problem is just occured in ERD. I should design a tree structure database like catalogue-catalogue-catalogue-item. and ...
        Dear oneway, that is the key. Such problem is just occured in ERD. I should design a tree structure database like catalogue-catalogue-catalogue-item. and ...

        Level1
        |
        +--Level2
        |
        .......
        +-------Level100

        The number of level should be up to 100. There should be both category and item in each level. In my opinion, there should be the same table structure from level2 to level20 ( PK in the level and FK to the upper level). Now, even though I have thought it over when designing, I am still afraid that my boss will change his idea to add one column to all the tables.

        tks.
        • Try this SQL
          Why not try the following SQL query from ONE table?

          SELECT LPAD(\
        • Try this hierarchical query.
          Why not try the following SQL query.

          SELECT LPAD(\" \", 2*(LEVEL-1))||column1, column2, ...
          FROM table_name
          WHERE column1 like \"A%\"
          START WITH column1 = \"A\"
          CONNECT BY prior column1 = substr(column1, 1, length(column1) - 1);

          Result like:

          column1 column2 ...
          ------------ ------------
          A
          AA
          AAA
          AAB
          AB


          The \"LEVEL\", \"START WITH\", \"prior\" and \"CONNECT BY\" are the Oracle key words

          Note: LPAD(\" \"), \"A%\", \"A\" , the \" should be replaced by DAN1 YIN3 HAO4.
        • Tree structure should not be presented by all the level columns, but only by the column like parent_id. The poor design will bring you a lot trouble later.