Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何使用java时间格式在oracle中查询时区数据类型_Sql_Oracle_Oracle11g - Fatal编程技术网

Sql 如何使用java时间格式在oracle中查询时区数据类型

Sql 如何使用java时间格式在oracle中查询时区数据类型,sql,oracle,oracle11g,Sql,Oracle,Oracle11g,我有下面的时间戳,带有存储在表中的时区数据 create table sample(id number,last_modified_dt timestamp with time zone); select last_modified_dt from sample; last_modified_dt ----------------- 19-06-17 09:36:28.100452000 AM +00:00 我的前端node.js应用程序正在尝试使用以下格式进行查询 '2017-06-19

我有下面的时间戳,带有存储在表中的时区数据

create table sample(id number,last_modified_dt timestamp with time zone);

select last_modified_dt from sample;

last_modified_dt
-----------------
19-06-17 09:36:28.100452000 AM +00:00
我的前端node.js应用程序正在尝试使用以下格式进行查询

'2017-06-19T09:36:28Z' (java timestamp format)


select last_modified_dt from sample where last_modified_dt = '2017-06-19T09:36:28Z'
我试着用

select last_modified_dt from sample where last_modified_dt = TO_TIMESTAMP('2017-06-19T09:36:28Z','YYYY-MM-DD"T"HH24:MI:SS"Z"');

但是它返回的结果是空的,很明显我知道缺少了什么,你能帮我吗。

不是最好的解决方案,但是一个非常快速的解决方案是 如果你总是用那种格式来计算时间

   select last_modified_dt from sample 
    where TRUNC(last_modified_dt) = 
          TRUNC(to_date (regexp_replace ('2017-06-19T09:36:28Z',
                   '[a-zA-Z]',' '),
           'rrrr-mm-dd hh:mi:ss')) -- TRUNC can be added if only date is important for matching and time is not important.
REGEXP_REPLACE将从从Java获得的时间戳中删除任何字符的出现

a-ZA-Z将确保删除所有英文字母

如果db格式为
dd-mm-yyyy
,则仅当日期存储为字符时

select last_modified_dt from sample 
where TRUNC(last_modified_dt) = 
      TRUNC(to_date (regexp_replace ('2017-06-19T09:36:28Z',
               '[a-zA-Z]',' '),
       'rrrr-mm-dd hh:mi:ss'))

嗯,谢谢你的评论,但它仍然不起作用,因为db格式是dd-mm-yyyy,输入是yyy-mm-dd。有没有办法将带有时区的时间戳转换为日期格式?@AnishGopinath我认为这没有什么区别,你从SQL客户端看到的可能有不同的格式。当您使用
将输入转换为\u DATE
时,它应该与oracle匹配,不会出现问题
dd-mm-yyyy
可能是您根据设置在SQL客户端上看到的内容。monda:im获取ORA-01830:date格式图片在转换整个输入字符串之前结束错误更新了答案,此外,注释的正确用法是添加您所指的@AnishGopinath用户,并正确拼写:)我很确定它必须是
hh24
,而不是
hh