Oracle: SQL query that returns rows with only numeric values

前端 未结 6 494
抹茶落季
抹茶落季 2020-12-12 17:21

I have a field (column in Oracle) called X that has values like \"a1b2c3\", \"abc\", \"1ab\", \"123\", \"156\"

how do I write an sql query that returns me only the X

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 17:44

    What about 1.1E10, +1, -0, etc? Parsing all possible numbers is trickier than many people think. If you want to include as many numbers are possible you should use the to_number function in a PL/SQL function. From http://www.oracle-developer.net/content/utilities/is_number.sql:

    CREATE OR REPLACE FUNCTION is_number (str_in IN VARCHAR2) RETURN NUMBER IS
       n NUMBER;
    BEGIN
       n := TO_NUMBER(str_in);
       RETURN 1;
    EXCEPTION
       WHEN VALUE_ERROR THEN
          RETURN 0;
    END;
    /
    

提交回复
热议问题