为Oracle提供此视图

时间:2013-01-29 21:27:49

标签: sql sql-server-2008 oracle10g

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())

2 个答案:

答案 0 :(得分: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。而“+”则带有“||”s。最后,为了得到hh:mm:ss格式的经过时间,我使用了一个技巧。我采取不同之处,添加到当前日期,然后将小数部分转换为hh:mm:ss。

答案 1 :(得分: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)