tale852150
tale852150

Reputation: 1638

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;

/

Upvotes: 1

Views: 13479

Answers (4)

Maheswaran Ravisankar
Maheswaran Ravisankar

Reputation: 17920

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!

Upvotes: 0

Strauteka
Strauteka

Reputation: 198

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....

Upvotes: 0

tale852150
tale852150

Reputation: 1638

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;

/

Upvotes: 1

David Aldridge
David Aldridge

Reputation: 52376

Test whether:

v_string != upper(string)

or not.

Lookout for nulls.

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

Upvotes: 2

Related Questions