Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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
String 如何在Oracle中以字符串格式添加两次?_String_Oracle_Datetime_Time_Oracle Sqldeveloper - Fatal编程技术网

String 如何在Oracle中以字符串格式添加两次?

String 如何在Oracle中以字符串格式添加两次?,string,oracle,datetime,time,oracle-sqldeveloper,String,Oracle,Datetime,Time,Oracle Sqldeveloper,我有两个Oracle格式的时间字符串,都是HH24:MI:SS。我想把这两个加起来,得到十进制的结果(就像我们在Oracle中从一个日期时间减去另一个日期时间后得到的结果一样)。有什么帮助吗?试试这个 SELECT ( TO_DATE ( '13:00:00', 'HH24:MI:SS' ) - TO_DATE ( '12:00:00', 'HH24:MI:SS' ) ) AS DECI

我有两个Oracle格式的时间字符串,都是HH24:MI:SS。我想把这两个加起来,得到十进制的结果(就像我们在Oracle中从一个日期时间减去另一个日期时间后得到的结果一样)。有什么帮助吗?

试试这个

SELECT
      ( TO_DATE ( '13:00:00',
                'HH24:MI:SS' )
       - TO_DATE ( '12:00:00',
                'HH24:MI:SS' ) )
          AS DECIMALS,
      ( TO_DATE ( '13:00:00',
                'HH24:MI:SS' )
       - TO_DATE ( '12:00:00',
                'HH24:MI:SS' ) )
      * 24
          AS HOURS,
        ( TO_DATE ( '13:00:00',
                 'HH24:MI:SS' )
        - TO_DATE ( '12:00:00',
                  'HH24:MI:SS' ) )
      * 24
      * 60
          AS MINUTES,
        ( TO_DATE ( '13:00:00',
                 'HH24:MI:SS' )
        - TO_DATE ( '12:00:00',
                  'HH24:MI:SS' ) )
      * 24
      * 60
      * 60
          AS SECONDS
FROM
      DUAL;
回答

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
试试这个

SELECT
      ( TO_DATE ( '13:00:00',
                'HH24:MI:SS' )
       - TO_DATE ( '12:00:00',
                'HH24:MI:SS' ) )
          AS DECIMALS,
      ( TO_DATE ( '13:00:00',
                'HH24:MI:SS' )
       - TO_DATE ( '12:00:00',
                'HH24:MI:SS' ) )
      * 24
          AS HOURS,
        ( TO_DATE ( '13:00:00',
                 'HH24:MI:SS' )
        - TO_DATE ( '12:00:00',
                  'HH24:MI:SS' ) )
      * 24
      * 60
          AS MINUTES,
        ( TO_DATE ( '13:00:00',
                 'HH24:MI:SS' )
        - TO_DATE ( '12:00:00',
                  'HH24:MI:SS' ) )
      * 24
      * 60
      * 60
          AS SECONDS
FROM
      DUAL;
回答

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
试试这个

SELECT
      ( TO_DATE ( '13:00:00',
                'HH24:MI:SS' )
       - TO_DATE ( '12:00:00',
                'HH24:MI:SS' ) )
          AS DECIMALS,
      ( TO_DATE ( '13:00:00',
                'HH24:MI:SS' )
       - TO_DATE ( '12:00:00',
                'HH24:MI:SS' ) )
      * 24
          AS HOURS,
        ( TO_DATE ( '13:00:00',
                 'HH24:MI:SS' )
        - TO_DATE ( '12:00:00',
                  'HH24:MI:SS' ) )
      * 24
      * 60
          AS MINUTES,
        ( TO_DATE ( '13:00:00',
                 'HH24:MI:SS' )
        - TO_DATE ( '12:00:00',
                  'HH24:MI:SS' ) )
      * 24
      * 60
      * 60
          AS SECONDS
FROM
      DUAL;
回答

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
试试这个

SELECT
      ( TO_DATE ( '13:00:00',
                'HH24:MI:SS' )
       - TO_DATE ( '12:00:00',
                'HH24:MI:SS' ) )
          AS DECIMALS,
      ( TO_DATE ( '13:00:00',
                'HH24:MI:SS' )
       - TO_DATE ( '12:00:00',
                'HH24:MI:SS' ) )
      * 24
          AS HOURS,
        ( TO_DATE ( '13:00:00',
                 'HH24:MI:SS' )
        - TO_DATE ( '12:00:00',
                  'HH24:MI:SS' ) )
      * 24
      * 60
          AS MINUTES,
        ( TO_DATE ( '13:00:00',
                 'HH24:MI:SS' )
        - TO_DATE ( '12:00:00',
                  'HH24:MI:SS' ) )
      * 24
      * 60
      * 60
          AS SECONDS
FROM
      DUAL;
回答

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
你可以

  • 将时间字符串拆分为小时、分钟和秒
  • 将小时、分钟转换为秒,并将其全部相加
  • 将生成的秒数转换为间隔类型
  • 以所需格式从间隔类型中提取时间组件

查询1

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
查询2

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
你可以

  • 将时间字符串拆分为小时、分钟和秒
  • 将小时、分钟转换为秒,并将其全部相加
  • 将生成的秒数转换为间隔类型
  • 以所需格式从间隔类型中提取时间组件

查询1

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
查询2

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
你可以

  • 将时间字符串拆分为小时、分钟和秒
  • 将小时、分钟转换为秒,并将其全部相加
  • 将生成的秒数转换为间隔类型
  • 以所需格式从间隔类型中提取时间组件

查询1

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
查询2

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
你可以

  • 将时间字符串拆分为小时、分钟和秒
  • 将小时、分钟转换为秒,并将其全部相加
  • 将生成的秒数转换为间隔类型
  • 以所需格式从间隔类型中提取时间组件

查询1

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
查询2

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |

DECIMALS            HOURS   MINUTES SECONDS
0.0416666666666667  1       60      3600
with x as (
  select time1_,
         time2_,
         substr(time1_,1,2) * 3600 +
         substr(time1_,4,2) * 60   +
         substr(time1_,7,2)            as time1_secs,
         substr(time2_,1,2) * 3600 +
         substr(time2_,4,2) * 60   +
         substr(time2_,7,2)            as time2_secs
  from mytab
  ),
y as (
  select time1_,time2_,
         numtodsinterval(time1_secs + time2_secs,'second') time_intvl
from x
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from y
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |
with x as (
  select time1_,
         time2_,
         numtodsinterval(
           (substr(time1_,1,2) + substr(time2_,1,2) )* 3600 +
           (substr(time1_,4,2) + substr(time2_,4,2) ) * 60  +
            substr(time1_,7,2) + substr(time2_,7,2) 
           , 'second'
           ) as time_intvl
  from mytab
  )
select time1_, time2_,
       extract(day from time_intvl) days,
       extract(hour from time_intvl) hours,
       extract(minute from time_intvl) minutes,
       extract(second from time_intvl) seconds,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) duration
from x
|   TIME1_ |   TIME2_ | DAYS | HOURS | MINUTES | SECONDS | DURATION |
|----------|----------|------|-------|---------|---------|----------|
| 12:30:00 | 05:50:55 |    0 |    18 |      20 |      55 | 18:20:55 |
| 18:48:56 | 15:33:55 |    1 |    10 |      22 |      51 | 34:22:51 |

十进位还是什么?小时、秒或分钟?就所有三个时间而言,加上两个日期是毫无意义的。“12:00:00”add(+)“15:00:00”表达式的预期结果是什么?此外,如果您计划执行日期/时间算术,则需要使用to_date()函数将时间字符串转换为日期数据类型,转换后的日期部分将添加到当前月份的第一天,因此上述表达式将变为01-10-2013 12:00:00+01-10-2013 15:00:00。这个加法不会产生有意义的结果。Oracle不允许将日期添加到datedecimal interms或什么?小时、秒或分钟?就所有三个时间而言,加上两个日期是毫无意义的。“12:00:00”add(+)“15:00:00”表达式的预期结果是什么?此外,如果您计划执行日期/时间算术,则需要使用to_date()函数将时间字符串转换为日期数据类型,转换后的日期部分将添加到当前月份的第一天,因此上述表达式将变为01-10-2013 12:00:00+01-10-2013 15:00:00。这个加法不会产生有意义的结果。Oracle不允许将日期添加到datedecimal interms或什么?小时、秒或分钟?就所有三个时间而言,加上两个日期是毫无意义的。“12:00:00”add(+)“15:00:00”表达式的预期结果是什么?此外,如果您计划执行日期/时间算术,则需要使用to_date()函数将时间字符串转换为日期数据类型,转换后的日期部分将添加到当前月份的第一天,因此上述表达式将变为01-10-2013 12:00:00+01-10-2013 15:00:00。这个加法不会产生有意义的结果。Oracle不允许将日期添加到datedecimal interms或什么?小时、秒或分钟?就所有三个时间而言,加上两个日期是毫无意义的。“12:00:00”add(+)“15:00:00”表达式的预期结果是什么?此外,如果您计划执行日期/时间算术,则需要使用to_date()函数将时间字符串转换为日期数据类型,转换后的日期部分将添加到当前月份的第一天,因此上述表达式将变为01-10-2013 12:00:00+01-10-2013 15:00:00。这个加法不会产生有意义的结果。Oracle不允许将日期添加到日期