Find out if field value is only letter

Dúvidas, dicas e truques de PL/SQL. Aqui também vão assuntos relacionados a pacotes, triggers, funções, Java-Stored Procedures, etc
Post Reply
pyro
Rank: DBA Sênior
Rank: DBA Sênior
Posts: 323
Joined: Thu, 21 Sep 2006 10:21 am
Location: Barala - TT

Personal, is there a more functional way to find out if the contents of a varchar2 is composed of letters only?
I thought about clearing special characters and numbers with Replace () and then measuring the size of the variable and compare with the original size if it is different because it had "trash".
But do this way it seems very mechanical, has anyone ever developed something more functional?
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

You can give a to_number and wait for an exception
pyro
Rank: DBA Sênior
Rank: DBA Sênior
Posts: 323
Joined: Thu, 21 Sep 2006 10:21 am
Location: Barala - TT

Okay, in this case you solve, but when I need to validate if only numbers came?
burga
Rank: DBA Pleno
Rank: DBA Pleno
Posts: 232
Joined: Thu, 26 Nov 2009 1:05 pm
Location: SP
Ricardo H. Tajiri

Hi Pyro,

in 10g / 11g You can find records that only have letters using regExp_Like.

Select all

WITH tabela AS ( 
  SELECT 'aaS123Iiouh' campo FROM DUAL 
  UNION ALL 
  SELECT 'aaSadsUIiouh' FROM DUAL 
  UNION ALL 
  SELECT 'aaSAAAIiouh' FROM DUAL 
  UNION ALL 
  SELECT '00' FROM DUAL 
  UNION ALL 
  SELECT '123a' FROM DUAL 
  UNION ALL 
  SELECT '' FROM DUAL) 
SELECT campo  
FROM tabela  
WHERE REGEXP_LIKE(campo,'^[[:alpha:]]+$');
I will leave home lesson the return of records that only have number ... change is minimal in this code and even half obvious ... : Wink:
Post Reply
  • Information
  • Who is online

    Users browsing this forum: Bing [Bot] and 1 guest