Removes all numeric digits from the string passed in. : Utility Function « Function Procedure Packages « Oracle PL/SQL Tutorial






SQL> CREATE OR REPLACE FUNCTION number_stripper(p_string VARCHAR2) RETURN VARCHAR2
  2  IS
  3     v_current_element NUMBER;
  4     v_char_length NUMBER;
  5     v_ret_val VARCHAR2 (2000);
  6     v_current_char VARCHAR2 (1);
  7  BEGIN
  8     v_char_length := LENGTH (p_string);
  9     v_current_element := 1;
 10
 11     LOOP
 12        EXIT WHEN v_current_element > v_char_length;
 13        v_current_char := SUBSTR (p_string, v_current_element, 1);
 14
 15        IF TRANSLATE (v_current_char, '1234567890', '**********') != '*'
 16           OR v_current_char = '~'
 17        THEN
 18           v_ret_val := v_ret_val || v_current_char;
 19        END IF;
 20
 21        v_current_element := v_current_element + 1;
 22     END LOOP;
 23
 24     RETURN (v_ret_val);
 25  END;
 26  /

Function created.

SQL> select number_stripper('asdf123') from dual;

NUMBER_STRIPPER('ASDF123')
--------------------------------------------------------------------------------
asdf

SQL>








27.26.Utility Function
27.26.1.Get nearest day
27.26.2.Compare date offset in a function
27.26.3.Create a procedure to count employees
27.26.4.To number or null
27.26.5.Removes all numeric digits from the string passed in.
27.26.6.Generic function utilizing dynamic SQL to return the number of rows in the specified table.
27.26.7.Get the Max date
27.26.8.String between function
27.26.9.Add day to month
27.26.10.Date time calculation function
27.26.11.Table Count function
27.26.12.Word count function
27.26.13.Define your own varchar to date function
27.26.14.Get the next business day
27.26.15.Format money
27.26.16.Date calculation: business days between
27.26.17.Convert Comma-separated values to table collection
27.26.18.Function to convert celsius to fahrenheit
27.26.19.Function to convert fahrenheit to celsius
27.26.20.Get circle area