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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:20:08+00:00 2026-06-04T11:20:08+00:00

I am trying to make a sub-table that stores a decode between two values,

  • 0

I am trying to make a sub-table that “stores” a decode between two values, because I need to use that decode multiple times. Let’s say these are my tables:

Table Person
Name    Number_name
Jeremy  One
Thomas  Two
Stephen Three

my current SQL looks like this:

SELECT
    decode (number_name,
    'one',1,
    'two',2,
    'three',3,
    'four',4)
    num
    FROM person where name = 'Jeremy'
    and (some other condition)
UNION SELECT
    decode (number_name,
    'one',1,
    'two',2,
    'three',3,
    'four,4)
    num
    FROM Person
    where Name <> "Jeremy"
    and (some other condition)

What I’d like to be able to do is something like this:

SELECT num from my_temp_table where name = "Jeremy" and (some other condition)
union select num from my_temp_table where name <> "Jeremy" and (some other condition)
...

where my_temp_table is constructed during that query (it ceases to exist when the query finishes running) and will look like

Table my_temp_table
Name  num
One   1
Two   2
Three 3
Four  4

And hopefully I can do this without the ol’ “select one name,1 num from dual union all …”

Is this doable?

  • 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-04T11:20:09+00:00Added an answer on June 4, 2026 at 11:20 am

    The WITH clause is sounds like the closest thing to what you’re describing. But that requires that you generate the data somehow. Selecting from DUAL is likely the easiest option

    WITH my_temp_table AS (
      SELECT 'One' name, 1 num from dual union all
      SELECT 'Two', 2 from dual union all
      SELECT 'Three', 3 from dual union all
      SELECT 'Four', 4 from dual
    )
    SELECT *
      FROM my_temp_table 
           JOIN person ON (<<some join condition>>)
     WHERE <<some predicate>>
    

    Since you don’t want to union a bunch of queries, you could do something like

    WITH my_temp_table AS (
      select level num,
             initcap( to_char( to_date( level, 'J' ),
                               'JSP' )) name
        from dual
     connect by level <= 4
    )
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the Win32 API to make a sub-thread that reads from
I'm trying to make a query that looks at a single table to see
I have been trying to make the sub-menu horizontal. In my HTML it looks
I am trying make long screen to vertical direction. So, I need a screen
Trying to make a custom :confirm message for a rails form that returns data
Trying to make a toggle button that hides/shows the right window/pane. Here is a
I am trying to make a duplicate of an existing NSManagedObject and related sub-objects
I'm trying to make mod_rewrite the first sub-directory string from url in order to
I am trying to make it so that when you click the corresponding subject
trying to make a page which will recursively call a function until a limit

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.