Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.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
Oracle 将h.mm格式的时间转换为分钟_Oracle_Oracle Sqldeveloper_Sqlplus - Fatal编程技术网

Oracle 将h.mm格式的时间转换为分钟

Oracle 将h.mm格式的时间转换为分钟,oracle,oracle-sqldeveloper,sqlplus,Oracle,Oracle Sqldeveloper,Sqlplus,我将时间以数字形式存储在oracle数据库中,格式为hh.mm,我想计算总和,然后使用存储过程将其以相同格式hh.mm写回另一列。 oracle中是否有用于这种求和的函数,或者我必须从头开始 提前感谢。您正在以自定义格式存储值。所以很明显Oracle不会有一个内置的函数来处理它 要做到这一点,需要一系列步骤,这些步骤可以封装到用户定义的函数中 将数字列转换为字符串。指定格式掩码很重要,否则下一步将产生错误的结果 使用正则表达式从列中提取小时和分钟值 用简单的算术推导出总分钟数 用简单的算术推导出

我将时间以数字形式存储在oracle数据库中,格式为hh.mm,我想计算总和,然后使用存储过程将其以相同格式hh.mm写回另一列。 oracle中是否有用于这种求和的函数,或者我必须从头开始


提前感谢。

您正在以自定义格式存储值。所以很明显Oracle不会有一个内置的函数来处理它

要做到这一点,需要一系列步骤,这些步骤可以封装到用户定义的函数中

  • 将数字列转换为字符串。指定格式掩码很重要,否则下一步将产生错误的结果
  • 使用正则表达式从列中提取小时和分钟值
  • 用简单的算术推导出总分钟数
  • 用简单的算术推导出新的总小时数和剩余分钟数
  • 将最终数字派生为伪十进制值
  • 这是SQL

    select hh + (mi/100) as final_result
    from (
      select trunc(step3.tot_mins/60) as hh
             , step3.tot_mins - (trunc(step3.tot_mins/60)*60) as mi
      from (
          select sum((step2.hh*60)+step2.mi) as tot_mins
          from (
            with step1 as (select to_char(ctime, '00000000000.99') ctime 
                       from your_table)
            select to_number(regexp_substr(ctime, '([0-9]+)', 1,1)) as hh
                   , to_number(regexp_substr(ctime, '([0-9]+)', 1, 2)) as mi
            from step1
               ) step2
        ) step3
      ) step4
    /
    
    。。。这是