Oracle - Select where field has lowercase characters

懵懂的女人 提交于 2019-12-03 10:12:10

How about this:

select id, first, last from mytable
where first != upper(first) or last != upper(last);

I think BQ's SQL and Justin's second SQL will work, because in this scenario:

first_name        last_name
----------        ---------
bob               johnson
Bob               Johnson
BOB               JOHNSON

I want my query to return the first 2 rows.

I just want to make sure that this will be an efficient query though - my table has 500 million rows in it.

When you say upper(first_name) != first_name, is "first_name" always pertaining to the current row that oracle is looking at? I was afraid to use this method at first because I was afraid I would end up joining this table to itself, but they way you both wrote the SQL it appears that the equality check is only operating on a row-by-row basis, which would work for me.

If you are looking for Oracle 10g or higher you can use the below example. Consider that you need to find out the rows where the any of the letter in a column is lowercase.

Column1
.......
MISS
miss
MiSS

In the above example, if you need to find the values miss and MiSS, then you could use the below query

SELECT * FROM YOU_TABLE WHERE REGEXP_LIKE(COLUMN1,'[a-z]');
Piyush K
 SELECT * 
 FROM mytable 
 WHERE FIRST_NAME IN (SELECT FIRST_NAME 
                      FROM MY_TABLE
                      MINUS 
                      SELECT UPPER(FIRST_NAME) 
                      FROM MY_TABLE )
Quyen ht

Try this:

SELECT * FROM YOU_TABLE WHERE REGEXP_LIKE(COLUMN1,'[a-z]','c'); => Miss, miss lower text
SELECT * FROM YOU_TABLE WHERE REGEXP_LIKE(COLUMN1,'[A-Z]','c'); => Miss, MISS upper text
Dave

for SQL server where the DB collation setting is Case insensitive use the following:

SELECT * FROM tbl_user WHERE LEFT(username,1) COLLATE Latin1_General_CS_AI <> UPPER(LEFT(username,1))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!