Oracle sort query

I have a problem with sorting a table field:

I have an working query:
SELECT distinct (f1 || ' - ' || substr(f2,'1','50')) as myfield
FROM mytab
where upper(f2) <> 'NOT DEFINED'
ORDER BY to_number(regexp_substr(f2,'^[0-9]+'))  desc

The above query works but I now need to add 'Not Defined' at the bottom of the list. I mean just add 'Not Defined' at the bottom of the above output.
But This query does not work:
(select 'Not Defined' as myfield from dual)
UNION
(
SELECT distinct (f1 || ' - ' || substr(f2,'1','50')) as myfield
FROM mytab
where upper(f2) <> 'NOT DEFINED'
ORDER BY to_number(regexp_substr(f2,'^[0-9]+'))  desc
)

Very strange

(
SELECT distinct (f1 || ' - ' || substr(f2,'1','50')) as myfield
FROM mytab
where upper(f2) <> 'NOT DEFINED'
ORDER BY to_number(regexp_substr(f2,'^[0-9]+'))  desc
)

The above query gives error (I only added start and close first bracket in the working query: ORA-009-7: missing right parenthesis. Could you help troubleshoot..?
toookiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
Remove the parans.  To add to the bottom, add a dummy sort something like(untested):

Select myfield from
(
select 2 sortOrder, null f2,'Not Defined' as myfield from dual
UNION all
SELECT 1 sortOrder, f2, distinct (f1 || ' - ' || substr(f2,'1','50')) as myfield
FROM mytab
where upper(f2) <> 'NOT DEFINED'
)
ORDER BY sortOrder, to_number(regexp_substr(f2,'^[0-9]+'))  desc

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
toookiAuthor Commented:
Thanks a lot for the help.
What you said worked perfectly. Never thought the way you mentioned.
Thanks.
0
slightwv (䄆 Netminder) Commented:
The dummy sort column comes in handy for just this reason.  I think most of us have used it at one time or another to force an order when one doesn't naturally exist.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.