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

  • SEARCH
  • Home
  • 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 7928181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:40:19+00:00 2026-06-03T19:40:19+00:00

I have a database table like this: id | check_number | amount 1 |

  • 0

I have a database table like this:

id   |   check_number        |   amount
1    |   1001]1002]1003      |   200]300]100
2    |   2001]2002           |   500]1000
3    |   3002]3004]3005]3007 |   100]300]600]200

I want to separate the records into something like this:

id   |   check_number    |   amount
1    |   1001            |   200
2    |   1002            |   300
3    |   1003            |   100
.    |     .             |    .
.    |     .             |    .
.    |     .             |    .

How do I do this just using SQL in Oracle and SQL Server?

Thanks,

Milo

  • 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-06-03T19:40:20+00:00Added an answer on June 3, 2026 at 7:40 pm

    In Oracle Only, using the CONNECT BY LEVEL method (see here), with several caveats:

    select rownum, id,
           substr(']'||check_number||']'
                  ,instr(']'||check_number||']',']',1,level)+1
                  ,instr(']'||check_number||']',']',1,level+1) 
                   - instr(']'||check_number||']',']',1,level) - 1) C1VALUE,
           substr(']'||amount||']'
                  ,instr(']'||amount||']',']',1,level)+1
                  ,instr(']'||amount||']',']',1,level+1) 
                   - instr(']'||amount||']',']',1,level) - 1) C2VALUE
        from table
    connect by id = prior id and prior dbms_random.value is not null  
          and level <= length(check_number) - length(replace(check_number,']')) + 1
    
    
    ROWNUM ID  C1VALUE C2VALUE
    
    1      1   1001    200
    2      1   1002    300
    3      1   1003    100
    4      2   2001    500
    5      2   2002    1000
    6      3   3002    100
    7      3   3004    300
    8      3   3005    600
    9      3   3007    200
    

    Essentially we blow out the query using the hierarchical functions of oracle and then only get the substrings for the data in each “column” of data inside the check_number and amount columns.

    Major Caveat: The data to be transformed must have the same number of “data elements” in both columns, since we use the first column to “count” the number of items to be transformed.

    I have tested this on 11gR2. YMMV depending on DMBS version as well. Note the need to use the “PRIOR” operator, which prevents oracle from going into an infinite connect by loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have database table like this +-------+--------------+----------+ | id | ip | date |
I always forget how to do things like this. I have a database table
I have a table like this in my database (SQL Server 2008) ID Type
I have a database application in which a group is modeled like this: TABLE
I have written a function to print database table to an array like this
I have a database that contains a table that looks a bit like this:
I have a table in a MSSQL database that looks like this: Timestamp (datetime)
I have a table in my postgresql 8.4 database like this: id(serial), event_type_id(id, foreign
that my problem: I have database table like that: id (AI) market_id 1 6
Say I have a database table like the following: FileID | FileName | FileSize

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.