Oracle SQL REG EXP

Dear Experts,

 How do I in Oracle SQL check if the field contain text with length 18 & contain [a..z,A..Z,0..9] chars only

Thanks
Jamil MuammarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alexander Eßer [Alex140181]Software DeveloperCommented:
create table test(id number, str varchar2(50));

insert into test values(1,  '123456789123456789');
insert into test values(2,  'abcdefghi123456789');
insert into test values(3,  'aA34567891234567zZ');
insert into test values(4,  '12345678912345678910');
insert into test values(5,  '.?3456789123456789');
insert into test values(6,  '_$3456789123456789');
insert into test values(7,  'xx123456789123456789');
insert into test values(8,  'AA123456789123456789');
insert into test values(9,  'foo 123456789123456789');
insert into test values(10, '  3456789123456789');

Open in new window


select a.str,
       length(a.str)
  from test a
 where regexp_like(a.str, '[[:alnum:]]{18}')
   and length(a.str) = 18;

select a.str,
       length(a.str),
       regexp_instr(a.str, '[[:alnum:]]{18}')
  from test a
 where length(a.str) = 18;

Open in new window


http://sqlfiddle.com/#!4/30060/11
0
slightwv (䄆 Netminder) Commented:
Slight modification that removes the length check:
select a.str,
       length(a.str)
  from test a
 where regexp_like(a.str, '^[[:alnum:]]{18}$');
   

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.