0

SQL Server 中的这个视图正在获取我们然后根据管理时间显示的记录,我现在需要在 Oracle 10g 中执行此操作,我必须在这里转换什么样的差异?

    /* Formatted on 1/29/2013 3:39:19 PM (QP5 v5.227.12220.39724) */
SELECT p.facility_key,
       CAST (p.unit_code AS VARCHAR) + '-' + CAST (p.room AS VARCHAR)
      AS unit_code,
       p.first_name,
       p.last_name,
       m.admin_time,
     CONVERT (varchar (5),
            datediff (s,
                  m.admin_time,
                  getdate ())
          / 3600)
       + ':'
       + CONVERT (varchar (5),
          datediff (s,
                m.admin_time,
                getdate ())% 3600 / 60)
              AS ELAPSED
FROM         OTEN.TEN_M_PATIENT_MAST AS P INNER JOIN
              OP.ORD_M_ADMIN AS M ON P.PAT_NUMBER = M.PAT_NUMBER
WHERE     (M.ADMIN_TIME BETWEEN DATEADD(DAY, - 1, GETDATE()) AND GETDATE())
4

2 回答 2

2

如果您经过的时间少于 24 小时,那么以下应该可以工作:

SELECT P.FACILITY_KEY,
       CAST(P.UNIT_CODE AS VARCHAR(255)) || '-' || CAST(P.ROOM AS VARCHAR(255)) AS UNIT_CODE,
       P.FIRST_NAME, P.LAST_NAME, M.ADMIN_TIME,
       to_char(trunc(sysdate)+(SYSDATE - m.admin_time), 'hh:mm:ss') as elapsed
FROM OTEN.TEN_M_PATIENT_MAST P INNER JOIN
     OP.ORD_M_ADMIN M
     ON P.PAT_NUMBER = M.PAT_NUMBER
WHERE M.ADMIN_TIME BETWEEN sysdate - 1 and sysdate

一些笔记。首先,我在varchar. 您应该在任何数据库中执行此操作。其次,我简化了日期时间算法,只使用减法。我getdate()改为sysdate. 以及带有“||”的“+”。最后,为了获得 hh:mm:ss 格式的经过时间,我使用了一个技巧。我取差值,添加到当前日期,然后将小数部分转换为 hh:mm:ss。

于 2013-01-29T22:12:57.807 回答
1

尝试这个:

 /* Formatted on 1/29/2013 4:00:43 PM (QP5 v5.227.12220.39724) */
SELECT p.facility_key,
       CAST (p.unit_code AS VARCHAR) || '-' || CAST (p.room AS VARCHAR)
      AS unit_code,
       p.first_name,
       p.last_name,
       m.admin_time,
     TO_CHAR (  (SYSDATE- m.admin_time)
          / 3600)
       || ':'
       || TO_CHAR ((SYSDATE- m.admin_time) MOD 3600 / 60)
              AS elapsed
FROM         oten.ten_m_patient_mast  p INNER JOIN
              op.ord_m_admin m ON p.pat_number = m.pat_number
WHERE     (m.admin_time BETWEEN (SYSDATE -1) AND SYSDATE)
于 2013-01-29T22:21:23.877 回答