'PL/SQL - I want to test if a character string contains 1 or more lower-case letters

Using PL/SQL (Oracle 11gR2) I want an IF statement that tests if a string contains 1 or more lower-case letters.

PL/SQL pseudo-code:

declare
v_string varchar2(100) := 'John';

begin
if v_string contain lower-case letter then
  ... do this
else
  ... do something else
end if;
end;

/



Solution 1:[1]

Answered my own question but accidentally put it in 'comments'. Here it is:

declare
   name varchar2(200) := 'John';
begin
 if regexp_like(name,'[:lower:]') then
   dbms_output.put_line('lowercase');
 else
    dbms_output.put_line('uppercase');
 end if;
end;

/

Solution 2:[2]

Test whether:

v_string != upper(string)

or not.

Lookout for nulls.

coalesce(v_string,'X') != coalesce(upper(string),'X')

Solution 3:[3]

declare
   v_name varchar2(200) := 'JOHn';
begin
 if regexp_like(v_name,'[:lower:]') then
   dbms_output.put_line('first test lowercase');
 else
    dbms_output.put_line('first test uppercase');
 end if;

 IF v_name != UPPER(v_name) THEN
  dbms_output.put_line('second test lowercase');


 ELSE
 dbms_output.put_line('second test uppercase');
 END IF;
end;

test it ... output

first test uppercase

second test lowercase

David Aldridge is correct....

Solution 4:[4]

if(v_string != upper(string) AND regexp_count(string,'[[:alpha:]]' > 0 )
then
   -- Has Lower case
end if

It also checks, if the string contains any alphabets!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 David Aldridge
Solution 3 Strauteka
Solution 4 Maheswaran Ravisankar