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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:20:54+00:00 2026-05-25T01:20:54+00:00

An SQL statement like: select * from ( select ‘000000000000’ as x from dual

  • 0

An SQL statement like:

select * from (
  select '000000000000' as x from dual
  union
  select '978123456789' as x from dual
  union 
  select 'B002AACD0A' as x from dual
) /*where x>'000000000000'*/ order by x;

Yields:

B002AACD0A
000000000000
978123456789

After uncommenting the WHERE-restriction, the result is:

B002AACD0A
978123456789

I would have expected the result to be just 978123456789 since B002AACD0A is returned before 000000000000 when running the query without restriction.

How can this behavior be explained? And how am I supposed to sort and compare varchars so that they can work together like I can do with integers?

Funny enough, when changing the restriction to x>'B002AACD0A', the result is empty. Changing it tox>978123456789 returns B002AACD0A.

I.e. when comparing:

B002AACD0A > 978123456789 > 000000000000

But when sorting:

978123456789 > 000000000000 > B002AACD0A 

When using binary sort explicitely (order by NLSSORT(x,'NLS_SORT=BINARY_AI')), the result is B002AACD0A>978123456789>000000000000 and matches the behavior of comparison. But I still do not know why this is happening.

  • 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-25T01:20:54+00:00Added an answer on May 25, 2026 at 1:20 am

    Peter,

    the behaviour of the sorting is regulated by the NLS_SORT session parameter, whereas the behaviour for comparisons is dependent upon the NLS_COMP parameter. You must have a mismatch.

    I obtain the same result as you do with the following parameters:

    SQL> SELECT *
      2    FROM nls_session_parameters
      3   WHERE parameter IN ('NLS_COMP', 'NLS_SORT');
    
    PARAMETER                      VALUE
    ------------------------------ ----------------------------------------
    NLS_SORT                       FRENCH
    NLS_COMP                       BINARY
    

    However when the two are matched the result is consistent:

    SQL> alter session set nls_comp=LINGUISTIC;
    
    Session altered
    
    SQL> select * from (
      2    select '000000000000' as x from dual
      3    union
      4    select '978123456789' as x from dual
      5    union
      6    select 'B002AACD0A' as x from dual
      7  ) /*where x>'000000000000'*/ order by x;
    
    X
    ------------
    B002AACD0A
    000000000000
    978123456789
    
    SQL> select * from (
      2    select '000000000000' as x from dual
      3    union
      4    select '978123456789' as x from dual
      5    union
      6    select 'B002AACD0A' as x from dual
      7  ) where x > '000000000000' order by x;
    
    X
    ------------
    978123456789
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pseudo SQL statement like select [orderid], [productname], [price], [productid_FK] from Order
If i have a parameterized SQL statement like this: SELECT * FROM table WHERE
I want to write an SQL statement like below: select * from tbl where
I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0;
I have a SQL statement that looks like: SELECT [Phone] FROM [Table] WHERE (
i have sql statement like this SELECT DISTINCT results_sp_08.material_number FROM results_sp_08 INNER JOIN courses
Here's my current SQL statement: SEARCH_ALBUMS_SQL = SELECT * FROM albums WHERE title LIKE
so if i do a SQL statement like so: sql = SELECT * FROM
When I have a sql statement like select * from table1 , it works
If I want to run an SQL statement like SELECT integername from tblintegerlist where

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.