Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Check a string for only alphanumeric value.

KalpataruJun 30 2017 — edited Jul 1 2017

Hi ALL,

I need to test or check a string for alphanumeric values i.e only alphabets either A to Z in capitals or a to z in small letters and number 0 to 9 are allowed

except these no other values are allowed or others values are not allowed.

Oracle DataBase Version : 11.2.0.4.0.

my test cases.

--------------------

--Both AplhaNumeric

-----------------------

SELECT REGEXP_INSTR('!@!@!@','^[a-zA-Z0-9]+$') FROM DUAL; --Results 0 is correct because of special chracters.

Output

------

0

--Results 1 which is incorrect because only number and no alphabets are present in the string , it should be retrun 0

SELECT REGEXP_INSTR('213123213','^[a-zA-Z0-9]+$') FROM DUAL;

Output

------

1

--Results 1 which is incorrect because only alphabets and no numbers are present in the string , it should be retrun 0

SELECT REGEXP_INSTR('asdsadasd','^[a-zA-Z0-9]+$') FROM DUAL;

Output

------

1

--Is Correct because these string contains alphanumeric

SELECT REGEXP_INSTR('asdsadasd213123','^[a-zA-Z0-9]+$') FROM DUAL;

Output

------

1

--Same wrong result in these sql also

SELECT LENGTH(TRIM(TRANSLATE('weasdasd123213213', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', ' '))) FROM DUAL;

SELECT REGEXP_INSTR('wqeqwewqe','^[[:alnum:]]+$') FROM DUAL;

SELECT REGEXP_INSTR('dsada213123','[a-zA-Z0-9]*') FROM DUAL;

SELECT COUNT(*) FROM DUAL WHERE REGEXP_LIKE('123123asdasd','^[a-zA-Z0-9]*$');

Any help is appreciated.

This post has been answered by Hans Steijntjes on Jun 30 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 29 2017
Added on Jun 30 2017
11 comments
14,761 views