Use SQL fuzzy matching to verify whether a field is a date format

Source: Internet
Author: User
Tags rtrim

Recently you need to verify that a field in the Data warehouse is converted to a date format, such as timestamp format ' 2016-05-03 23:21:35.0 ',

However, DB2 does not support regexp_like (matching) functions, so you need to rethink other options.

The final use of the most common like to fuzzy matching, although less than the regular match so accurate, but also enough.

Ideas:

An underscore represents a character, and that ' 2016-05-03 23:21:35.0 ' can be expressed as ' ____-__-__-__.__.__.______ '.

Of course, this method is rather stupid, do not recognize whether it is a number or a letter or a character, of course, the better way is to write a UDF (custom function) to achieve regular matching.

SELECT emp_id, Timestamp,rtrim (CAST (TIMESTAMP as CHAR)) Dtfrom TEST. Emptabwhere RTRIM (CAST (TIMESTAMP as CHAR ())) Not like ' ____-__-__-__.__.__.______ ' with UR;

Use SQL fuzzy matching to verify whether a field is a date format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.