Solved

Oracle SQL to find mixed case string values

Posted on 2016-08-08
11
72 Views
Last Modified: 2016-08-08
Hello Experts,

I'm trying to find values for a specific string field in an Oracle 12c database that contains mixed case letters. Can anyone help me with the correct syntax for accomplishing this? My field name is "dc.dscr". Thank you.
0
Comment
Question by:jsmith08
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 31

Expert Comment

by:awking00
Comment Utility
Can you provide a little more definition on the kind of strings that meet you meaning of mixed case? (e.g. upper and lower case in the same word or capitalized words in the middle of a sentence, etc.)?
0
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
mixed case would mean it's not ALL-UPPER nor  ALL-LOWER.


select * from yourtable
where not (upper("dc.dscr") = "dc.dscr" or lower("dc.dscr") = "dc.dscr")

As a side node, if you can avoid it, I recommend not using quote-enclosed column names.
It's non-standard and makes your coding more cumbersome to use.
0
 

Author Comment

by:jsmith08
Comment Utility
I tried using:

 select * from dktcd dc
where not (upper('dc.dscr') = 'dc.dscr' or lower('dc.dscr') = 'dc.dscr')

but nothing is returned.

I want to be able to pull string values like the following:

Defendant ordered to attend Alcoholics Anonymous meetings ___ times per week.
Administrative license suspension (ALS) terminated.
Attorney of record is: ________________.

as opposed to just something like DEFT TO BE ASSESSED WHILE IN CUSTODY
0
 
LVL 31

Expert Comment

by:awking00
Comment Utility
Are you just trying to retrieve strings that are not all upper or lower case? If so ,then slight revision to sdstuber's method -
where dc.dscr != upper(dc.dscr) or dc.dscr != lower(dc.dscr)
0
 
LVL 4

Expert Comment

by:Abhimanyu Suri
Comment Utility
select 'Defendant ordered to attend Alcoholics Anonymous meetings ___ times per week.
Administrative license suspension (ALS) terminated.
Attorney of record is: ________________.' from dual


select * from v$sqlarea where upper(sql_text) like upper('%Defendant ordered%')

Above is an example, by putting upper on both sides, I was able to fetch the entire string.

Please note that using upper may degrade performance.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
Comment Utility
you changed what I posted  (note you changed double quotes, to single quotes) , but based on your change, I'm going to guess you want this

 select * from dktcd dc
 where not (upper(dc.dscr) = dc.dscr or lower(dc.dscr) = dc.dscr)
0
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
but just in case the double quotes are required try this...    

 select * from dktcd dc
  where not (upper(dc."dscr") = dc."dscr" or lower(dc."dscr") = dc."dscr")


(again, don't try changing double quotes to single quotes)
0
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
also note,  awking00's  "slight revision" of my query  does NOT work.

EVERY not null string will always be found by that revision.

use one of the versions I posted.

rearranging the conditiosn of my query would use "and" not "or"  between the two negations

select * from dktcd dc
where dc.dscr != upper(dc.dscr) and dc.dscr != lower(dc.dscr)
0
 

Author Comment

by:jsmith08
Comment Utility
Ok, I tried using

select * from dktcd dc
 where not (upper(dc.dscr) = dc.dscr or lower(dc.dscr) = dc.dscr)

without any quotes and it works as desired. Thank you very much! I thought I needed to include the quotes for some reason.

I also tried using

select * from dktcd dc
 where dc.dscr != upper(dc.dscr) or dc.dscr != lower(dc.dscr)

but it returns values with all upper case letters in addition to values with upper and lower case letters.
0
 
LVL 31

Expert Comment

by:awking00
Comment Utility
Should have been AND and not OR :-(
0
 

Author Comment

by:jsmith08
Comment Utility
Thank you everyone for your help.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now