简体   繁体   English

oracle sql时间比较

[英]oracle sql time comparison

I have this oracle table and the following data:我有这个 oracle 表和以下数据:

CREATE TABLE data( 
 fielda DATE DEFAULT sysdate, //sample data: 06/02/2021
  fieldb TIMESTAMP(6) WITH LOCAL TIME ZONE DEFAULT current_timestamp //sample data:05/02/2021 11:44:04.000000000
);

I want to list all records in table data, where timea is not equal to timeb.我想列出表数据中的所有记录,其中 timea 不等于 timeb。

I wrote this query:我写了这个查询:

select * from  data where TO_DATE(timea, 'dd/mm/yyyy') != TO_DATE(timea, 'dd/MM/yyyy hh24:mi:ss') ;

but i get error: ORA-01830: date format picture ends before converting entire input string但我得到错误: ORA-01830: date format picture ends before converting entire input string

Do advise how to list all records in table a, where timea is not equal to timeb.请告知如何列出表 a 中的所有记录,其中 timea 不等于 timeb。

oracle basic data types: date and timestamp are two different data types. oracle 基本数据类型:日期和时间戳是两种不同的数据类型。 the last one is more percise.最后一个更精确。 your to_date conversion seems very wired.您的 to_date 转换似乎很连贯。 to_date convert a string (text format) to a date. to_date 将字符串(文本格式)转换为日期。 according your table defination, fielda is a date type.根据您的表格定义, fielda 是日期类型。 why do the convert?为什么要转换? what is the parameter timea?什么是参数timea? to_date(timea,...),= to_date(timea...?) whats your point, supporsed you are try to query some record which not match the specified date. to_date(timea,...),= to_date(timea...?) 你的意思是什么,支持你尝试查询一些与指定日期不匹配的记录。 the where clause should be like " where sometable,somefiled != to_date('specified_date_string_with_format','specified_format')" where 子句应该类似于“ where sometable,somefiled != to_date('specified_date_string_with_format','specified_format')”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM