Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7442675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:12:42+00:00 2026-05-29T11:12:42+00:00

Possible Duplicate: How to best split csv strings in oracle 9i I have some

  • 0

Possible Duplicate:
How to best split csv strings in oracle 9i

I have some legacy data where there’s a VARCHAR2(100) field SUBID that has comma-delimited data:

empno   subid
1       1, 3, 2
2       18,19, 3, 6, 9

etc.

I need to write the equivalent of

select * 
  from table 
 where id in ( select SUBID from subidtable where empno = 1 )

Is there a way to accomplish this in Oracle?

Edit:

Added some clarification. I need to do the IN clause against the values stored in a string from a single row, not all rows.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:12:43+00:00Added an answer on May 29, 2026 at 11:12 am

    You can, but it’s a little ugly. Depending on the Oracle version

    You can use a variant of this askTom thread to parse the data into a collection and use the collection in your SQL statement. This should work in any version of Oracle since 8.1.5 but the syntax has gotten a bit simpler over the years.

    SQL> create or replace type myTableType as table
      2       of varchar2 (255);
      3  /
    
    Type created.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  create or replace
      2       function in_list( p_string in varchar2 ) return myTableType
      3    as
      4        l_string        long default p_string || ',';
      5        l_data          myTableType := myTableType();
      6        n               number;
      7    begin
      8      loop
      9          exit when l_string is null;
     10          n := instr( l_string, ',' );
     11          l_data.extend;
     12          l_data(l_data.count) :=
     13                ltrim( rtrim( substr( l_string, 1, n-1 ) ) );
     14          l_string := substr( l_string, n+1 );
     15     end loop;
     16     return l_data;
     17*  end;
    SQL> /
    
    Function created.
    
    SQL> select ename
      2    from emp
      3   where empno in (select column_value
      4                     from table( in_list( '7934, 7698, 7521' )));
    
    ENAME
    ----------
    WARD
    BLAKE
    MILLER
    

    You can also use regular expressions as discussed in this StackOverflow thread

    SQL> ed
    Wrote file afiedt.buf
    
      1  select ename
      2    from emp
      3   where empno in (select regexp_substr(str, '[^,]+',1,level)
      4                     from (select '7934, 7698, 7521' str from dual)
      5*                 connect by level <= regexp_count(str,'[^,]+'))
    SQL> /
    
    ENAME
    ----------
    WARD
    MILLER
    BLAKE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to best split csv strings in oracle 9i can you help
Possible Duplicate: Best way to stop SQL Injection in PHP I have seen some
Possible Duplicate: Best practice: Import mySQL file in PHP; split queries How to import
Possible Duplicate: Best Way to Sprite Images? Hi i have been using this http://spritegen.website-performance.org
Possible Duplicate: Best way to detect integer overflow in C/C++ i have tried to
Possible Duplicate: Best practices in error reporting (Mathematica) Assume that I have a function
Possible Duplicate: best way to clear contents of .NET’s StringBuilder Is there a quick
Possible Duplicate: Split string, convert ToList<int>() in one line… i have a string that
Possible Duplicate: Best way to detect integer overflow in C/C++ If I have an
Possible Duplicate: Best Way to Sprite Images? I have the following image that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.