本文介绍了检查字符串是否为有效日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
我有一个带有 sourcefilename 字段的表,它有 5 条记录.以下是记录.
I have a table with field sourcefilename which has 5 records. Following are the records.
SN. SOURCEFILENAME
1. 20170215095453_1.Iredell Memorial Hospital Dental Eligibility.xls_INFREPT01.txt
2. Iredell Memorial Hospital Eligibility April 2017.xls_INFREPT01.txt
3. Iredell Memorial Hospital Eligibility March 2017.xls_INFREPT01.txt
4. Iredell Memorial Hospital Eligibility May 2017.xls_INFREPT01.txt
5. Iredell Memorial Hospital October 2016 Dental Eligibility.xls_EligData.txt
我只需要提取前 8 个字符并检查其是否为有效日期.如果它是一个有效日期,则返回 TRUE,否则返回 FALSE.
I just need to extract first 8 characters and check if its a valid date. If it is a valid date then return TRUE else FALSE.
我尝试过 ISDATE 函数.还有其他选择吗?
I tried ISDATE function. Is there are any other alternatives?
SELECT DISTINCT SubStr(sourcefilename,1,8),
CASE WHEN isdate(SubStr(sourcefilename,1,8),'YYYYMMDD') = 1 THEN 'TRUE' ELSE 'FALSE' END FROM ai_4451_1_metl;
推荐答案
Oracle 12.2 提供了一个新功能 VALIDATE_CONVERSION.到目前为止,我从未使用过它,但我认为它会是这样的:
Oracle 12.2 provides a new function VALIDATE_CONVERSION. So far I never used it, but I assume it would be like this:
CASE VALIDATE_CONVERSION(SubStr(sourcefilename,1,8) AS DATE, 'YYYYMMDD')
WHEN 1 THEN 'TRUE'
ELSE 'FALSE'
END
这篇关于检查字符串是否为有效日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!