简体   繁体   中英

Select rows that has mixed charcters in a single value e.g. 'Joh?n' in name column

In an oracle table:

1- a value in a VARCHAR column contains characters that are not letters.

Consider a scenarion where a name in 'last_name' column contains regular characters (A - Z, a - z) as well as characters that are not english letters (eg '.', '-', ' ','_', '>' or similar).

The challenge is to select the rows that has names in 'last_name' as '.John' or 'John.' or '-John' or 'Joh-n'

2- Is it possible to have non-date values in a Date defined column? If yes, how can such records be selected in an oracle query?

Thanks!

I believe this will do the trick:

SELECT * FROM mytable WHERE REGEXP_LIKE(last_name, '[^A-Za-z]');

As for your 2nd question, I am unsure. I would be glad if someone else could add on to what I have to answer your 2nd question. I have found this website thought that might be of help. http://infolab.stanford.edu/~ullman/fcdb/oracle/or-time.html It explains the DATE format.

If I properly understand your goal, you need to select rows with last_name column containing the name 'John', but it may also have additional characters before, after, or even inside the name. In that case, this should be helpful:

select * from tab where regexp_replace(last_name, '[^A-Za-z]+', '') = 'John'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM