Adsense Ad

Wednesday, 25 October 2017

Oracle PL/SQL: Checking Alpha Numeric

  DECLARE
    CATLG VARCHAR2(50):='&VAL';
    ALPHA NUMBER:=0;
    NUMER NUMBER:=0;
    LEN NUMBER:= LENGTH(CATLG);
  BEGIN
    FOR I IN 1..LEN LOOP
      IF ASCII(SUBSTR(UPPER(CATLG),I,1)) BETWEEN 65 AND 90 THEN
        ALPHA:= ALPHA+1;
      END IF;
      IF SUBSTR(CATLG,I,1) IN ('0','1','2','3','4','5','6','7,','8','9') THEN
        NUMER:= NUMER+1;
      END IF;
    END LOOP;
    IF ALPHA = 0 THEN
      DBMS_OUTPUT.PUT_LINE 
('Alpha Numeric Mandatory Atleast single character required!');
      
    ELSIF NUMER = 0 THEN
      DBMS_OUTPUT.PUT_LINE 
('Alpha Numeric Mandatory Atleast single number required!');
      
   ELSE
      DBMS_OUTPUT.PUT_LINE ('Alpha Numeric String');
    END IF;  
  END;  

No comments: