PL/SQL (MOSC)

MOSC Banner

query output doubt

edited Jan 7, 2025 4:37PM in PL/SQL (MOSC) 3 commentsAnswered

Hi Team,

My Oracle version is 12c. I am executing below query.

query:

select id,TO_CHAR(end_date,'MM/DD/YYYY') AS end_date
from fund_id where id in
(2375340, 2374915, 2373796, 2373276, 2377976)
ORDER BY end_date DESC;

output:

ID

END_DATE

2375340

12/27/2024

2374915

12/26/2024

2373796

12/23/2024

2373276

12/20/2024

2377976

1/6/2025

Above output is incorrect as top end_date should be 01 jan 2025.

whereas if i am executing query using alias(as mentioned below). then its giving correct output as below:

query:

select id,TO_CHAR(end_date,'MM/DD/YYYY') AS end_date
from fund_id a where id in
(2375340, 2374915, 2373796, 2373276, 2377976)
ORDER BY a.end_date DESC;

output:

ID

END_DATE

2377976

1/6/2025

2375340

12/27/2024

2374915

12/26/2024

2373796

12/23/2024

2373276

12/20/2024

My question is why output is impacted if anything change in select query columns(to_char function applied in column end_date ) and allias not used. I think ideally select query column should not impact the order by clause output. Could anyone tell me if oracle is behaving correctly in this case.

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center