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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:34:30+00:00 2026-05-18T02:34:30+00:00

Consider the following scenario. I have a table (a stupid_table ) in a schema

  • 0

Consider the following scenario. I have a table (a stupid_table) in a schema over which I have no control. It’s third party, off limits. No touchy. I can query it, but not add indexes or new tables or change the design.

Every column in the stupid_table is a VARCHAR2(50 BYTE), there are lots of columns but I only need two of them: row_type and magic_number. The magic_number is populated with the string representation of an integer, but only where row_type is set to 'DATA', I only need the magic numbers that are greater than zero.

SELECT TO_NUMBER(magic_number)
FROM stupid_table
WHERE row_type = 'DATA'
AND TO_NUMBER(magic_number) > 0;

This results in an “invalid number” Oracle error, because the Cost Based Optimiser (CBO) is choosing to evaluate the TO_NUMBER before the checking the row_type and there’s a whole bunch of rows with a different row_type and a different use for the magic_number field.

OK, how about if I filter the rows first, and then do the comparison?

SELECT TO_NUMBER(t.magic_number)
FROM (
    SELECT magic_number
    FROM stupid_table
    WHERE row_type = 'DATA'
) t
AND TO_NUMBER(t.magic_number) > 0;

Now the CBO seems to work out that the query is quite simple and ignores the cunning that I have employed, yielding an identical query plan to the original.

Finally, in frustration, I resort to dirty hacks: using the /*+RULE*/ query hint to force Oracle to use the old Rule Based Optimiser. This works like a dream, but it shouldn’t be necessary, not to mention it’s using a feature of Oracle which is no longer supported.

Is there a better way to do this?

  • 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-18T02:34:30+00:00Added an answer on May 18, 2026 at 2:34 am

    Can you just avoid using TO_NUMBER altogether? Seems like that would improve performance anyways. Something like:

    WHERE t.magic_number != '0'
    

    If there could be negative numbers, or the numbers are floating point, you might need additional checks, but it certainly seems feasible.

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

Sidebar

Related Questions

From couple of days i am thinking of a following scenario Consider I have
Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider the following table structure: titles(titleID*, titleName) platforms(platformID*, platformName) products(platformID*, titleID*, releaseDate) publishers(publisherID*, publisherName)
I have kind of Listing application for iPhone application, which always calling a web
Consider the Following object model (->> indicates collection): Customer->Orders Orders->>OrderLineItems->Product{Price} The app is focused
I'm trying to select a column from a single table (no joins) and I
Background Users can pick dates as shown in the following screen shot: Any starting
What would anyone consider the most efficient way to merge two datasets using Python?
I have a few questions for you wise people involving OO design with Interfaces
After reading a lot of articles and many answers related to the above subject,

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.