Find UPPER Chars in a name column [message #622464] |
Tue, 26 August 2014 13:33 |
|
Yuvraaj
Messages: 122 Registered: January 2011 Location: California, USA
|
Senior Member |
|
|
Hello,
I'm trying to find the upper chars in a name field, but am getting whole word instead only UPPER case chars.
Please let me know what am missing.
sql>CREATE TABLE EMP(ENAME VARCHAR2(30));
Table created.
Elapsed: 00:00:00.15
sql>
sql>
sql>INSERT INTO EMP VALUES('JanuAry');
1 row created.
Elapsed: 00:00:00.09
sql>INSERT INTO EMP VALUES('mArcH');
1 row created.
Elapsed: 00:00:00.10
sql>
sql>INSERT INTO EMP VALUES('JulY');
1 row created.
Elapsed: 00:00:00.08
sql>INSERT INTO EMP VALUES('MAY');
1 row created.
Elapsed: 00:00:00.08
sql>INSERT INTO EMP VALUES('june');
1 row created.
Elapsed: 00:00:00.08
sql>select * from emp;
ENAME
------------------------------
JanuAry
mArcH
JulY
MAY
june
Elapsed: 00:00:00.17
sql> select ename from
(select REGEXP_SUBSTR (ename, '[^ ]+', 1, level) ename
from EMP
connect by level <= length(regexp_replace(ename,'[^ ]*'))+1
)
where regexp_instr(ename,'[A-Z]') > 0; 2 3 4 5 6
ENAME
------------------------------------------------------------------------------------------
JanuAry
mArcH
JulY
MAY
Elapsed: 00:00:00.17
sql>
Expected:
---
JA
AH
JY
MAY
---
Thanks.
|
|
|
|
|
Re: Find UPPER Chars in a name column [message #622468 is a reply to message #622467] |
Tue, 26 August 2014 13:55 |
|
Michel Cadot
Messages: 68645 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Also do NOT use standard table names for your test case, like EMP, DEPT...
SQL> col upchar format a10
SQL> with
2 data as (
3 select ename, substr(ename,column_value,1) ch, column_value cn
4 from emp,
5 table(cast(multiset(select level from dual connect by level <= length(ename))
6 as sys.odciNumberList))
7 where substr(ename,column_value,1)=upper(substr(ename,column_value,1))
8 )
9 select ename, listagg(ch) within group (order by cn) upchar
10 from data
11 group by ename
12 order by ename
13 /
ENAME UPCHAR
------------------------------ ----------
JanuAry JA
JulY JY
MAY MAY
mArcH AH
I bet Solomon will come with a nice query using XML features/functions avoiding the split+merge query.
[Updated on: Tue, 26 August 2014 13:56] Report message to a moderator
|
|
|
|
|
|
Re: Find UPPER Chars in a name column [message #622483 is a reply to message #622472] |
Wed, 27 August 2014 00:41 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
SQL> column u_str format A10;
SQL> with t as (
2 select 'JanuAry' str from dual union all
3 select 'mArcH' from dual union all
4 select 'JulY' from dual union all
5 SELECT 'MAY' FROM DUAL UNION ALL
6 SELECT 'june' FROM DUAL UNION ALL
7 select 'juneJUNE' from dual
8 )
9 SELECT Regexp_replace(str, '[a-z]', '') u_str
10 FROM t;
U_STR
----------
JA
AH
JY
MAY
JUNE
6 rows selected.
Regards,
Lalit
|
|
|
Re: Find UPPER Chars in a name column [message #622485 is a reply to message #622483] |
Wed, 27 August 2014 00:54 |
|
Michel Cadot
Messages: 68645 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Solomon's solution is better as it does not make any assumption on characters that are not upper case one.
Yours assumes that these other characters are only minuscules.
As OP's query (even wrong) checks white spaces, we can assume there can be at least some white spaces.
|
|
|