Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Oracle For Fun
Hello Daniel,
> Write a simple function that will return a Boolean (True/False) as to
> whether something has the format of a valid telephone number with area
> code. It must check for the following:
>
> Three integers between 0 and 9
> Followed by a dash '-'
> Followed by three integers between 0 and 9
> Followed by a dash '-'
> Followed by four integers
> The length must be 12.
>
> Hint: When I run the following query:
> select * from user_source where name = <function_name>;
> it returns only 7 lines of code.
Given:
create table t1(x varchar2(20));
insert into t1 values('123-456-7893'); insert into t1 values('12-3456-7893'); insert into t1 values('-12345-67893'); insert into t1 values('123-456-7893'); insert into t1 values('1a3-456-7893'); insert into t1 values('123-456-78s3');
This should do it:
select case when
length(translate(x, '0123456789-', '9999999999')) = 10 and length(translate(x, '-0123456789', '*')) = 2 and instr(x, '-') = 4 and instr(x, '-', -1) = 8 then 'Valid' else 'Invalid' end
Valid
Invalid
Invalid
Valid
Invalid
Invalid
Rgds.
VC Received on Wed Jan 28 2004 - 21:17:41 CST
![]() |
![]() |