Solved

Oracle SQL to find mixed case string values

Posted on 2016-08-08
11
109 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 32

Expert Comment

by:awking00
ID: 41747727
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
ID: 41747748
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
ID: 41747777
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 32

Expert Comment

by:awking00
ID: 41747787
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
ID: 41747804
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
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 41747807
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
ID: 41747811
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
ID: 41747816
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
ID: 41747838
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 32

Expert Comment

by:awking00
ID: 41747853
Should have been AND and not OR :-(
0
 

Author Comment

by:jsmith08
ID: 41747871
Thank you everyone for your help.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can i Import Access Table Into Oracle Using Toad 36 166
Repeat query 13 46
TSQL query to generate xml 4 31
SQL Error - Query 6 24
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

813 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

10 Experts available now in Live!

Get 1:1 Help Now