使用Oracle 11g获取非日期值的值

使用Oracle 11g获取非日期值的值,oracle,oracle11g,Oracle,Oracle11g,我的表中有两列是insertDate和ModifiedDate,它们不是日期数据类型,而是varchar。 当我查询该表时,我在该日期列中插入了奇怪的字符,比如//此时。下一次可能是别的。 我不想讨论这个值是如何得到的,这很复杂 我现在只需要使用Oracle11g从这两列中查询这些值?比如: Select insertDate,ModifiedDate from mytable where IsDate(insertDate ) <> 'NO' OR IsDate(Modif

我的表中有两列是insertDate和ModifiedDate,它们不是日期数据类型,而是varchar。 当我查询该表时,我在该日期列中插入了奇怪的字符,比如//此时。下一次可能是别的。 我不想讨论这个值是如何得到的,这很复杂

我现在只需要使用Oracle11g从这两列中查询这些值?比如:

 Select insertDate,ModifiedDate 
 from mytable
 where IsDate(insertDate ) <> 'NO' OR IsDate(ModifiedDate) <> 'NO'
选择insertDate,ModifiedDate
从mytable
其中IsDate(插入日期)“否”或IsDate(修改日期)“否”

是否有类似inOracle 11g的函数可以帮助我获取这些非日期值?

您可以基于创建一个函数,然后使用它检查您的值:

create or replace function checkDate(v in varchar2) return varchar2 is
    d date;
begin
    d :=to_date(v, 'FXMM/DD/YYYY');
    return 'OK';
exception
    when others then
        return 'KO';    
end;
它的作用是:

with test(col) as (
    select '11/30/2017' from dual union all
    select '11/30//2017' from dual union all
    select '11-30-2017' from dual union all
    select '11/30/17' from dual
)    
select col, checkDate(col)
from test
给出:

COL         CHECKDATE 
----------- ----------
11/30/2017  OK        
11/30//2017 KO        
11-30-2017  KO        
11/30/17    KO     

日期列中怎么会有奇怪的字符?您可能有varchar列。考虑到这一点,你必须知道你认为哪一种格式有效或不适用于一个日期,以应用一个检查,对不起,我的意思是它们不是日期数据类型,是VARCHAR2OK,但是你必须理解你想正确的格式。锿。2018年1月1日,2018年1月18日,2018年1月1日,…我认为任何可以转换为日期的日期。理论上,即使是“2018年1月1日”也可以…:)你需要一些规则