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 7788963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:08:43+00:00 2026-06-01T21:08:43+00:00

I need to split a string from one table into two columns in another

  • 0

I need to split a string from one table into two columns in another table. There are a few different variety of numbers and rules but no clear delimiter. Can I use combo of SUBSTR and INSTR or do I need to use if-then loops in PL/SQL to satisfy all the rules?

Input Table

5 Kent Street 
3 A lindt Street
2/15 bold Street 
9/34-36 carmen Road
12/5a sandford Street

Result

Number  |Street
--------------------
5       |Kent Street
3A      |lindt Street
2/15    |bold Street
9/34-36 |carmen Road
12/5a   |sandford Street
  • 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-01T21:08:44+00:00Added an answer on June 1, 2026 at 9:08 pm

    I wouldn’t do this in pl/sql, it is really unnecessary.

    Oracle SQL has REGEXP_SUBSTR, REGEXP_REPLACE, REGEXP_COUNT. You also have IF and CASE expressions you can put in the SELECT clause. Go to the SQL reference, FUNCTIONS section: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions.htm#i1482196

    Your dataset has some interesting variations – letters and fractions in the house/building number. What you don’t have (yet) is street names in multiple parts (e.g. Melnea Cass Boulevard here in Boston) or street names with concatenated/missing (“Broadway”) or unusual (“Cedar Passway”) ‘street’ designators.

    Start with sample_data as a refactored query to hold your input data. You’ll probably have a table or view or something instead.

    For now we are holding the assumption that each street name has two words. We start by counting them with REGEXP_COUNT. This is the subquery COUNTED_DATA with value WORDS as the count of words. Note I append a space to each line of input, in case there isn’t one at the end of the input row of data, so that the count is correct.

    I search for each word as

    [^ ]+[ ]+
    

    That is, one or more non-spaces followed by one or more spaces. I don’t want to use zero or more spaces ([ ]*) because that is ambiguous.

    Then we use a regular expression to pick out the last two words and the first (words minus 2) words.

    Here’s the result:

    with sample_data as (
        select '5 Kent Street' as addr from dual
        union all select '3 A lindt Street' as addr from dual
        union all select '2/15 bold Street' as addr from dual
        union all select '9/34-36 carmen Road' as addr from dual
        union all select '12/5a sandford Street' from dual
    )
    select 
        counted_data.addr as "Original Address",
        substr (regexp_replace (addr || ' ', '(([^ ]+[ ]+){' || (words-2) ||'})([^ ].*)','\1'), 1, 10) as "Number",
        substr (trim (regexp_replace (addr || ' ', '(([^ ]+[ ]+){' || (words-2) ||'})([^ ].*)','\3')), 1, 25) as "Street"
    from
    (
        select sample_data.addr, regexp_count(addr || ' ', '[ ]+') as words
        from sample_data
    ) counted_data
    
    Original Address      Number     Street                   
    --------------------- ---------- -------------------------
    5 Kent Street         5          Kent Street               
    3 A lindt Street      3 A        lindt Street              
    2/15 bold Street      2/15       bold Street               
    9/34-36 carmen Road   9/34-36    carmen Road               
    12/5a sandford Street 12/5a      sandford Street           
    

    To make this readable I used ‘substr’ to cut down the length of the output columns. (“COLUMN” doesn’t work in SQL Developer.)

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

Sidebar

Related Questions

I need to split a string into two parts. The string contains words separated
I need to split comma delimited string into a second columns I have the
I need to split my string input into an array at the commas. Is
I need to split a string into chunks of 2,2,3,3 characters and was able
I need to split a string without removing the separators. Is there a simple
In C# I need to split a string (a log4j log file) into array
I am trying to take a data string from one column and split it
I need to split a string and print it beginning from bottom on my
I need split string by commas and spaces, but ignore the inside quotes, single
I need to split the string result of the autocomplete plugin . I know

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.