CREATE OR REPLACE FUNCTION hex_to_dec ( pc$hex IN VARCHAR2 )
RETURN PLS_INTEGER
IS
hexch VARCHAR2(40) := UPPER( pc$hex) ;
len PLS_INTEGER := LENGTH( hexch) ;
res PLS_INTEGER := 0 ;
pos PLS_INTEGER := 0 ;
val PLS_INTEGER ;
car VARCHAR2(1) ;
BEGIN
FOR i IN REVERSE 1..len LOOP
car := SUBSTR( hexch, i , 1 ) ;
IF ASCII(car) > 57 THEN
val := ASCII(car) - 55 ;
ELSE
val := ASCII(car) - 48 ;
END IF ;
res := res + (val * ( POWER(16,pos) ) ) ;
pos := pos + 1 ;
END LOOP ;
RETURN( res ) ;
END;
/