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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:48:35+00:00 2026-06-15T14:48:35+00:00

I realise that the structure of the data in database I am working with

  • 0

I realise that the structure of the data in database I am working with leaves a lot to be desired, but I have no control over that, so bear with me.

What I have is a field ADDRESSES.COMPANY that may or may not be an integer ID. Sometimes it’s a string. When it is an integer, however, I want to do a join to another table COMPANIES. The original query (pre-join) looks like this:

SELECT *
  FROM (SELECT ROWNUM AS ROW_NUM, INNERQUERY.*
          FROM (  SELECT *
                    FROM ADDRESSES, COMPANIES
                ) INNERQUERY) OUTERQUERY
 WHERE ROW_NUM <= 50 AND ROW_NUM > 0

If I try to join normally, I get an error ORA-01722: invalid number… for obvious reasons (it’s not always a number to attempt to join on, or at least I assume that’s what it must mean because it’s true!). My query after trying to join:

SELECT *
  FROM (SELECT ROWNUM AS ROW_NUM, INNERQUERY.*
          FROM (  SELECT *
                    FROM ADDRESSES, COMPANIES
                    WHERE ADDRESSES.COMPANY(+) = COMPANIES.ID
                ) INNERQUERY) OUTERQUERY
 WHERE ROW_NUM <= 50 AND ROW_NUM > 0

The only two potential solutions I can come up with are both using the TO_NUMBER() function, which I assumed would evaluate a non-numerical string to 0. I tried:

SELECT *
  FROM (SELECT ROWNUM AS ROW_NUM, INNERQUERY.*
          FROM (  SELECT *
                    FROM ADDRESSES, COMPANIES
                    WHERE TO_NUMBER(ADDRESSES.COMPANY)(+) = COMPANIES.ID
                ) INNERQUERY) OUTERQUERY
 WHERE ROW_NUM <= 50 AND ROW_NUM > 0

which errors with ORA-00936: missing expression (on line 7). I assumed my guess at the appropriate place to use it was incorrect and tried the following instead:

SELECT *
  FROM (SELECT ROWNUM AS ROW_NUM, INNERQUERY.*
          FROM (  SELECT *, TO_NUMBER(ADDRESSES.COMPANY) AS COMPANYID
                    FROM ADDRESSES, COMPANIES
                    WHERE COMPANYID(+) = COMPANIES.ID
                ) INNERQUERY) OUTERQUERY
 WHERE ROW_NUM <= 50 AND ROW_NUM > 0

which errors with ORA-00923: FROM keyword not found where expected on line 3.

When my first attempt didn’t work, I was sure that my second would. But I am baffled by the error. Am I just completely clueless about Oracle syntax and/or behaviour, or is it something else? Is there a solution to my problem?

  • 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-15T14:48:37+00:00Added an answer on June 15, 2026 at 2:48 pm

    1.

    WHERE TO_NUMBER(ADDRESSES.COMPANY)(+) = COMPANIES.ID

    You cannot do this.

    The (+) operator can be applied only to a column, not to an arbitrary
    expression. However, an arbitrary expression can contain one or more
    columns marked with the (+) operator.

    JOINS

    2.

    SELECT *, TO_NUMBER(ADDRESSES.COMPANY) AS COMPANYID
      FROM ADDRESSES, COMPANIES
     WHERE COMPANYID(+) = COMPANIES.ID
    

    You cannot reference a column by alias in the same scope this alias was defined (unless it is an order by clause).

    The correct way to perform an outer join in this case would be to use ansi join syntax:

    select * 
      from companies
      left join addresses on companies.id = addresses.companyid
    

    It doesn’t make much sense to use to_number on string columns, as it will yield you the same invalid number error on the first non-numeric value it encounters during join.

    You may try, however, casting number to char, as it has been advised.

      select * 
          from companies
           left join addresses 
             on to_char(companies.id) = addresses.companyid
    

    But you have to keep in mind that it would probably drop your perfomance, as you won’t be able to use index whenever you transform your column.

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

Sidebar

Related Questions

I have a data structure that accepts an abstract class in the c'tor. I'd
I realise that the Java 8 lambda implementation is subject to change, but in
I realise that similar questions have been asked before however none of the solutions
I realise there might be similar questions but I couldn't find one that was
I am looking for a data structure in C that allows me to declare
I am using Delphi 2009. I have a very simple data structure, with 2
I have a data structure, for which I am currently using an ArrayList .
I realise that you can open the google maps app ready for directions by
I realize that a SO user has formerly asked this question but it was
I have a database filled with records in the following format: . What 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.