regular express in oracle sql statement - numeric format btween xxxxxx and xx-xx-xx

Hi,

I have select sql statement and it shouldnt distinguish two types of formats. Currently, I have:

...
...
rank() over(partition by kki_nbr order by discharge_date desc)
...
...

And kki_nbr can be following two formats:
xxxxxx
xx-xx-xx

ex)
123456
12-34-56

these two formats should consider as same value.
so, how do I detect those two formats as same format?

thanks,
dkim18Asked:
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.

warhaugCommented:
Try to remove the delimiter as this so you will get the same format
... partition by replace(kki_nbr,'-') order by ...
0
dkim18Author Commented:
I can't remove delimiter. This is the entire query:

SELECT kki_nbr, record_id, last_name, first_name,  dob, room_nbr, service, admit_date, discharge_date
from
(
select kki_nbr, record_id, last_name, first_name,  dob, room_nbr, service, admit_date,discharge_date,
rank() over(partition by kki_nbr order by discharge_date desc)rn
from attending_ip                                                        
where last_name like 'DAN%' and first_name like '%'
 
  ORDER BY last_name,first_name,kki_nbr, admit_date
)
where rn = 1

+++++++++++++++

If I use this:

SELECT kki_nbr, record_id, last_name, first_name,  dob, room_nbr, service, admit_date, discharge_date
from
(
select kki_nbr, record_id, last_name, first_name,  dob, room_nbr, service, admit_date,discharge_date,
rank() over(partition by kki_nbr order by discharge_date desc)rn
from attending_ip                                                        
where last_name like 'DANIELS%' and first_name like '%' and
REGEXP_LIKE(kki_nbr, '^([[:digit:]]{2}-[[:digit:]]{2}-[[:digit:]]{2}|[[:digit:]]{6}$')
 
  ORDER BY last_name,first_name,kki_nbr, admit_date
)
where rn = 1


I got this error:

'invalid relational operator' error.

0
SujithData ArchitectCommented:
Which line are you getting the error?
The ORDER BY is not requierd. And there is an extra bracket in your regex. The below query seems ok to me.

SELECT kki_nbr, record_id, last_name, first_name,  dob, room_nbr, service, admit_date, discharge_date
from
( 
select kki_nbr, record_id, last_name, first_name,  dob, room_nbr, service, admit_date,discharge_date,
rank() over(partition by kki_nbr order by discharge_date desc)rn
from attending_ip                                                         
where last_name like 'DANIELS%' and first_name like '%' and 
REGEXP_LIKE(kki_nbr, '^[[:digit:]]{2}-[[:digit:]]{2}-[[:digit:]]{2}|[[:digit:]]{6}$')
)
where rn = 1

Open in new window

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

dkim18Author Commented:
it doesn't say which line:

>[Error] Script lines: 1-10 -------------------------
 ORA-00920: invalid relational operator 


BTW, where do I have extra bracket?
0
Jinesh KamdarCommented:
Pls confirm the below : -

1. Your DB is really Oracle 10g (want to be sure even though I see u have posted in that zone)
2. kkr_nbr is one of the following types - CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB
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
dkim18Author Commented:
jinesh_kamdar,

thanks for pointing that. I thought the DB is 10g, but it is 9i and we are upgrading it to 10g this weekend, so I will test after that and then give you the points!
0
Jinesh KamdarCommented:
I thought so, since wen I ran that query on my 9i DB, it threw the same "Invalid Relational Operator" error instead of the standard "Invalid Identifer" error :)
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.