Oracle SQL 劈開字串

來源:互聯網
上載者:User

標籤:

一、資料範例

二、劈開單行

SELECT id_,REGEXP_SUBSTR(name_, ‘[^,]+‘, 1, rownum) h2  FROM  (select id_,name_ from test_reg_count t  where t.id_ =2 )CONNECT BY level <= length(name_)-length(replace(name_,‘,‘,‘‘))+1;--或者SELECT id_,REGEXP_SUBSTR(name_, ‘[^,]+‘, 1, rownum) h2  FROM  (select id_,name_ from test_reg_count t  where t.id_ =2 )CONNECT BY REGEXP_SUBSTR(name_, ‘[^,]+‘, 1, rownum) is not null;

三、劈開多行

SELECT id_,REGEXP_SUBSTR(name_, ‘[^,]+‘, 1, level) name_  FROM  test_reg_count   CONNECT BY level <= length(name_)-length(replace(name_,‘,‘,‘‘))+1                AND name_ = PRIOR name_                 AND PRIOR dbms_random.value <1;       --或者SELECT id_,REGEXP_SUBSTR(name_, ‘[^,]+‘, 1, level) name_  FROM  test_reg_count   CONNECT BY level <= length(name_)-length(replace(name_,‘,‘,‘‘))+1                AND name_ = PRIOR name_                 AND PRIOR SYS_GUID() is not null;

這裡最重要的是 prior操作符,關於prior的解釋Oracle的官方文檔是這麼描述的:

  In a hierarchical query, one expression in the CONNECT BY condition must be qualified by the PRIOR operator. If the CONNECT BY condition is compound, then only one condition requires the PRIOR operator, although you can have multiple PRIOR conditions. PRIOR evaluates the immediately following expression for the parent row of the current row in a hierarchical query.

  PRIOR is most commonly used when comparing column values with the equality operator. (The PRIOR keyword can be on either side of the operator.) PRIOR causes Oracle to use the value of the parent row in the column. Operators other than the equal sign (=) are theoretically possible in CONNECT BY clauses. However, the conditions created by these other operators can result in an infinite loop through the possible combinations. In this case Oracle detects the loop at run time and returns an error.

Oracle SQL 劈開字串

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.