Mistři v programování na #hovnokod

SQL #379

CREATE OR REPLACE VIEW my_schema.my_view AS
SELECT 
   TO_NUMBER (c.payment_term_code) ID, 
   c.payment_term_code sap_code, c.payment_term_name longname,
          c.short_name shortname, c.comment_line comments, c.cust_relevant, c.vend_relevant, c.active active,
          c.updated_by created_by, c.updated_by updated_by, c.updated_on created_on, c.updated_on updated_on, 1 txn_ver
     FROM my_schema.my_table c
    WHERE (    LENGTH (c.payment_term_code) = 1
           AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
          )
       OR (    LENGTH (c.payment_term_code) = 2
           AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
           AND SUBSTR (c.payment_term_code, 2, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
          )
       OR (    LENGTH (c.payment_term_code) = 3
           AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
           AND SUBSTR (c.payment_term_code, 2, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
           AND SUBSTR (c.payment_term_code, 3, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
          )
       OR (    LENGTH (c.payment_term_code) = 4
           AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
           AND SUBSTR (c.payment_term_code, 2, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
           AND SUBSTR (c.payment_term_code, 3, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
           AND SUBSTR (c.payment_term_code, 4, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
          )
       OR (    LENGTH (c.payment_term_code) = 5
           AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
           AND SUBSTR (c.payment_term_code, 2, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
           AND SUBSTR (c.payment_term_code, 3, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
           AND SUBSTR (c.payment_term_code, 4, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
           AND SUBSTR (c.payment_term_code, 5, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
          )
   UNION
   SELECT ID, sap_code, longname, shortname, comments, 'Y', 'Y', active, created_by, updated_by, created_on, updated_on, 1
     FROM my_schema.my_other_table) tt

HovnoKod,