Validation to detect text in numeric field

admin 2018.05.19 20:20 Views : 226

DECLARE
  v_test_nbr NUMBER;
  v_check_exists NUMBER;
BEGIN
  BEGIN
    v_test_nbr := to_number(:P6_TEXT_FIELD);
  EXCEPTION
  WHEN OTHERS THEN
    -- or catch 1722 (invalid number) and 6502 (char to number conversion error)
    v_test_nbr := NULL;
  END;

  IF v_test_nbr IS NOT NULL
  THEN
  -- if v_test_nbr is not null then the field should be numerically valid
  -- if it isn't then this code would be skipped and this validation
  -- will not throw an error.
  -- However, the previous validation will still fail when text is entered, 
  -- so this shouldn't matter.
    BEGIN
      SELECT 1
      INTO v_check_exists
      FROM my_table
      WHERE column_name = :P6_TEXT_FIELD;
    EXCEPTION 
    WHEN no_data_found THEN
      v_check_exists := 0;
    END;

    IF v_check_exists = 1 
    THEN
      RETURN 'A record with this key already exists';      
    END IF;
  END IF;

  RETURN NULL;
END;
No. Subject Author Views Date
32 PHOTO SIZE 줄이기 admin 230 2025.11.23
31 ATACCESS admin 234 2024.03.02
30 꿈 - 08/26/2018 admin 450 2018.08.26
29 Medwigs admin 426 2018.07.17
28 TABLE PRINT admin 425 2018.06.18
27 FOOTER admin 445 2018.06.16
26 SQL CODE (1) admin 424 2018.06.16
25 GP PRINT admin 230 2018.05.31
24 How to convert DATE to NUMBER admin 246 2018.05.27
23 DATE Compare admin 246 2018.05.22
22 If you want to use EXISTS in a PL/SQL function returning BOOLEAN admin 251 2018.05.19
21 use a validation function for an element in apex 5.0 admin 248 2018.05.19
» Validation to detect text in numeric field admin 226 2018.05.19
19 All Data DELETE from Table admin 248 2018.05.10
18 Process admin 246 2018.05.05
17 소식 궁금 합니다. 감사또감사 435 2018.05.21
16 HTTP ERROR 500 admin 1136 2018.05.14
15 05/10/2018 - SET UP admin 435 2018.05.10
14 05/04/2018 admin 424 2018.05.04
13 05/04/2018 admin 407 2018.05.04