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?
 
Jinesh KamdarConnect With a Mentor Commented:
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
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
sujith80Commented:
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
 
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
 
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
All Courses

From novice to tech pro — start learning today.