如何在Oracle SQL中指定时间戳格式

如何在Oracle SQL中指定时间戳格式,sql,oracle,date,datetime,timestamp,Sql,Oracle,Date,Datetime,Timestamp,它以一种非常糟糕的方式表现出来,但我需要一小时:一分钟 SELECT DepName, ARRSTATIONNAME, VEHICLENUMBER, ARRVTIME - DEPTIME FROM VEHICLENUMBER... ARRVTIME-DEPTIME是我需要进行格式化的地方,因为我得到了rn +000000000 02:28:00.000000 看起来你在处理时间戳。如果是这样,请看下面的示例: 样本表: SQL> create table test (arrvtime

它以一种非常糟糕的方式表现出来,但我需要一小时:一分钟

SELECT DepName, ARRSTATIONNAME,  VEHICLENUMBER, ARRVTIME - DEPTIME FROM VEHICLENUMBER...
ARRVTIME-DEPTIME
是我需要进行格式化的地方,因为我得到了rn

+000000000 02:28:00.000000

看起来你在处理时间戳。如果是这样,请看下面的示例:

样本表:

SQL> create table test (arrvtime timestamp, deptime timestamp);

Table created.

SQL> insert into test values (systimestamp, systimestamp - 0.2);

1 row created.

SQL> select * From test;

ARRVTIME                        DEPTIME
------------------------------- -------------------------------
08.05.20 21:04:50,508000        08.05.20 16:16:50,000000
您可能需要的查询:

SQL> select arrvtime - deptime diff,
  2         extract(hour from arrvtime - deptime) hours,
  3         extract(minute from arrvtime - deptime) minutes,
  4         --
  5         -- what you want
  6         extract(hour  from arrvtime - deptime) ||':'||
  7         extract(minute from arrvtime - deptime) result
  8  from test;

DIFF                                 HOURS    MINUTES RESULT
------------------------------- ---------- ---------- ------
+000000000 04:48:00.508000               4         48 4:48

SQL>

看起来你在处理时间戳。如果是这样,请看下面的示例:

样本表:

SQL> create table test (arrvtime timestamp, deptime timestamp);

Table created.

SQL> insert into test values (systimestamp, systimestamp - 0.2);

1 row created.

SQL> select * From test;

ARRVTIME                        DEPTIME
------------------------------- -------------------------------
08.05.20 21:04:50,508000        08.05.20 16:16:50,000000
您可能需要的查询:

SQL> select arrvtime - deptime diff,
  2         extract(hour from arrvtime - deptime) hours,
  3         extract(minute from arrvtime - deptime) minutes,
  4         --
  5         -- what you want
  6         extract(hour  from arrvtime - deptime) ||':'||
  7         extract(minute from arrvtime - deptime) result
  8  from test;

DIFF                                 HOURS    MINUTES RESULT
------------------------------- ---------- ---------- ------
+000000000 04:48:00.508000               4         48 4:48

SQL>

请发布示例数据和所需输出。我已将您的问题编辑成格式,请花些时间并遵循发布指南。请参阅“请发布样本数据和所需输出”。我已将您的问题编辑成格式,请花些时间并遵循发布指南。请看Tho的小兴趣,当分钟数是个位数,如3:2时,您如何处理?不客气。至于你的最后一个问题:提取也会提取它们,没有区别。如果您的意思是如何格式化它,例如2分钟显示为02(带前导零),那么请使用LPAD:
LPAD(extract(minute from diff),2,'0')
Tho如果您不感兴趣的话,当分钟数是个位数(如3:2)时,您如何处理它们?不客气。至于你的最后一个问题:提取也会提取它们,没有区别。如果您的意思是如何格式化它,例如2分钟显示为02(前导零),那么使用LPAD:
LPAD(extract(minutes from diff),2,'0')