Values in a field in Oracle are separated by commas (,).

Source: Internet
Author: User

Multiple values in a field in Oracle separated by commas (,) have encountered abnormal problems recently. A field has a field association relationship with another table, the Unit Field stores multiple IDs separated by commas (,). There are quite a few people who have found this problem online, I sorted out some questions for a netizen and turned to www.2cto.com Table a: a_usr_id (string type, usr_id of associated table B) 123,124,125 Table B: usr_id, usr_name, 123 name1 124 name2 125 name3 use SQL statements directly without using stored procedures to obtain such a data set: www.2cto.com name1, name2, name3 solution: SQL> select * from test; a_URS_ID limit 123,125 123,124,125 SQL> select * from test1; URS_ID URS_NAME ---------- -------------------- 123 name1 124 name2 125 name3 SQL> with split_data as (select key, rn, substr (str, instr (str, ',', 1, rn) + 1, instr (str, ',', 1, rn + 1)-instr (str, ',', 1, rn) -1) str from (select a_urs_id key, ',' | a_urs_id | ', 'str from test) a, (select rownum rn from dual connect by rownum <10) B where instr (str, ',', 1, rn + 1)> 0) select key, substr (max (sys_connect_by_path (urs_name, ','), 2) a_name from split_data a, test1 B where. str = B. urs_id start with rn = 1 connect by key = prior key and rn-1 = prior rn group by key; KEY A_NAME ------------------ limit 123,124,125 name1, name2, name3 123,125 name1, name3

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.