How to check if a string contains only number and alphabetic characters?
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: How to check if a string contains only number and alphabetic characters?

  1. #1
    Join Date
    Apr 2001
    Posts
    125

    How to check if a string contains only number and alphabetic characters?

    Hi, guys,

    I try to write a stored procedure to check if a string column contains specifial characters, I loop through each row of the table, then loop through each letter of the string, then do the following compare:

    IF

    (ascii(SUBSTR(string1, i, 1)) <= 47)
    OR
    (ascii(SUBSTR(string1, i, 1)) >= 58 AND ascii(SUBSTR(string1, i, 1)) <= 64)
    OR
    (ascii(SUBSTR(string1, i, 1)) >= 91 AND ascii(SUBSTR(string1, i, 1)) <= 96)
    OR
    (ascii(SUBSTR(string1, i, 1)) >= 123 AND ascii(SUBSTR(string1, i, 1)) <= 127)

    THEN

    it is a string contains special characters

    END IF

    But the performance is very bad because this table is huge, is there another way to do this?

    Thanks

  2. #2
    Join Date
    Jan 2001
    Posts
    2,828
    Hi

    Have you narrowed down the list of special characters ?
    if yes then you can do a couple of things

    1)Upgrade to 10g and use its regex feautures

    2)Write a Java or a C regex function and call that from
    within sql



    regards
    Hrishy
    Last edited by hrishy; 09-21-2005 at 03:02 PM.

  3. #3
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    Code:
    IF TRANSLATE (UPPER(l_string),
                  '#0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                  '#') IS NOT NULL
    THEN
    
    it is a string contains special characters
    
    END IF
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width