Oracle SQL converts a varchar type data into multiple rows of Result Records

Source: Internet
Author: User


Oracle SQL converts a varchar type data into multiple rows of Results records. Today, when I create a report, I want to use an SQL query to query the final results. However, I encountered some problems during implementation, one field I found is varchar type, and a combination of multiple IDs (for example, 1, 2, 3, and the result is implemented by a selete Statement ), however, I want to query this id in another table, and this id is of the int type. Therefore, if you cannot directly use this result, an error is always reported indicating that the number type is invalid. Later, I found a way to convert the result into a record of the corresponding row. For example, www.2cto.com: the result of this field is 3, 4. select replace (appr_or_reasons, '|', ''', ''') from equ_odr_trade_ovr_request where id = 21748; the following statement can convert this value: 34 with temp as (select '3, 4' text from dual) select regexp_substr (text, '[0-9] +', 1, rn) text from temp t1, (select level rn from dual connect by rownum <= (select length (text)-length (replace (text, ',') + 1 from temp )) at the end of t2, I can directly put the preceding statement into the in clause. Select cor. credit_or_reason from sds_credit_or_reason cor where id in (with temp as (select replace (appr_or_reasons, '|', ''', ''') from equ_odr_trade_ovr_request where id = 21748) id from dual) select regexp_substr (id, '[0-9] +', 1, rn) id from temp t1, (select level rn from dual connect by rownum <= (select length (id)-length (replace (id, ',', '') + 1 from temp )) t2 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.