[英]Oracle: VarChar(hh24:mm:ss) - timestamp, how to?
I'm used to SQL Server and datediff, time data types. 我习惯了SQL Server和datediff,时间数据类型。 Pulling my hair out trying to figure this out. 试图弄清楚我的头发。
Column 1: Timestamp Column 2: Varchar(200) in the form HH24:MM:SS 第1列:时间戳记第2列:Varchar(200),格式为HH24:MM:SS
Trying to do: 尝试做:
SELECT Varchar(200) - Timestamp AS Difference
FROM table
Can't figure out the right way to do this, queries are getting ridiculously complicated. 由于找不到正确的方法,查询变得异常复杂。
Here is a possible oracle select statement to solve your problem. 这是一个可能的oracle select语句来解决您的问题。
A simple explanation of the code: select to_date(char) - to_date(to_char(date)) as difference from table; 代码的简单说明:选择to_date(char)-to_date(to_char(date))作为与表的区别; you need to convert the varchar(200) to date and convert the timestamp to the same date format in varchar then finally convert the timestamp varchar into date format. 您需要将varchar(200)转换为日期,并将时间戳转换为varchar中相同的日期格式,然后最终将时间戳varchar转换为日期格式。
That should work. 那应该工作。
select to_date('17:15:30', 'HH24:MI:SS')- to_date(to_char(systimestamp, 'HH24:MI:SS'), 'HH24:MI:SS') as difference from dual;
Here are few date/timestamp/interval manipulation examples, hope this helps: 以下是一些日期/时间戳/间隔操作示例,希望对您有所帮助:
SELECT
TO_DSINTERVAL('0 ' || timeinstring) - NUMTODSINTERVAL(TO_CHAR(timestamp, 'SSSSS'), 'SECOND') RESULT_AS_INTERVAL,
TRUNC(timestamp) + (TO_DSINTERVAL('0 ' || timeinstring) - NUMTODSINTERVAL(TO_CHAR(timestamp, 'SSSSS'), 'SECOND')) RESULT_AS_DATE,
TO_CHAR(DATE'1-1-1' + (TO_DSINTERVAL('0 ' || timeinstring) - NUMTODSINTERVAL(TO_CHAR(timestamp, 'SSSSS'), 'SECOND')), 'HH24:MI:SS') RESULT_AS_TIMESTRING
FROM
(SELECT TIMESTAMP'2015-12-04 12:34:56' timestamp, '23:34:45' timeInString FROM DUAL) sample_data;
RESULT_AS_INTERVAL RESULT_AS_DATE RESULT_AS_TIMESTRING
---------------------------------- ------------------- --------------------
+000000000 10:59:49.000000000 04.12.2015 10:59:49 10:59:49
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.