0

我有 2 个查询。
我正在尝试加入他们,所以我只是从一个中写入导出,而不是在 excel 中手动加入它们。

(SELECT 
        b.OUT_NO, 
        a.ACCNO, 
        a.BILL_ACCNO, 
        a.NAME, 
        a.HOUSE_NO, 
        a.STREET, 
        a.HOUSE_NO2, 
        a.ZIP, 
        a.ID, 
        b.TIME_STAMP, 
        b.REST_DATE, 
        c.RESTORED_TIME, 
        b.OUT_CMNT
   FROM brook.account a, 
        brook.problem b, 
        brook.history c
  WHERE c.OUT_NO = b.OUT_NO 
    AND a.ID = c.ID 
    AND (  (a.NAME Is Not Null) 
       AND (a.DISC Is Null) 
       AND (b.TIME_STAMP>?) 
       AND (c.RESTORED_TIME<?))
)

(SELECT 
       b.OUT_NO, 
       a.ACCNO, 
       a.BILL_ACCNO, 
       a.NAME, 
       a.HOUSE_NO, 
       a.STREET, 
       a.HOUSE_NO2, 
       a.ZIP, 
       a.ID, 
       b.TIME_STAMP, 
       b.REST_DATE, 
       c.RESTORED_TIME, 
       b.OUT_CMNT
  FROM brook.account a, 
       brook.problem b, 
       brook.history c
 WHERE c.OUTAGE_NO = b.OUTAGE_NO 
   AND a.ID = c.ID 
   AND (   (a.NAME Is Not Null) 
       AND (a.DISC Is Null) 
       AND (b.TIME_STAMP > ? And b.TIME_STAMP < ?) 
       AND (c.RESTORED_TIME > ? And c.RESTORED_TIME < ?)
       )
)

我怎样才能加入这两个?进入 1,我试过UNION ALL但我得到了ora-01847 day of month must be between 1 and last day of month 错误。

?是参数,它链接到电子表格上的单元格。excel数据参数的格式。11/04/2013 00:00:00

谢谢

4

1 回答 1

0

错误与日期格式有关,与联合无关。
如果您将单元格值作为字符串参数传递,Oracle 会尝试将其转换为日期,以与表列中的列datetimestamp值进行比较。要进行此转换,Oracle 使用它的内部默认日期表示格式,这不适mm/dd/yyyy hh24:mi:ss用于您的情况。

有 2 种可能性来解决问题:

  1. 传递带date类型的参数以查询并将值转换为日期,然后再将其传递给 Oracle。查看MSDN 上的示例以及CreateParameterParameters.Append方法的描述。

  2. to_date使用Oracle 函数将查询中的值转换为日期。

更改查询中的条件

   AND (b.TIME_STAMP>?) 
   AND (c.RESTORED_TIME<?))

   AND (b.TIME_STAMP > ? And b.TIME_STAMP < ?) 
   AND (c.RESTORED_TIME > ? And c.RESTORED_TIME < ?)

   AND (b.TIME_STAMP > to_date(?,'mm/dd/yyyy hh24:mi:ss') ) 
   AND (c.RESTORED_TIME < to_date(?,'mm/dd/yyyy hh24:mi:ss') ))

   AND (
        b.TIME_STAMP > to_date(?,'mm/dd/yyyy hh24:mi:ss') 
        And 
        b.TIME_STAMP < to_date(?,'mm/dd/yyyy hh24:mi:ss')
       ) 
   AND (
        c.RESTORED_TIME > to_date(?,'mm/dd/yyyy hh24:mi:ss') 
        And 
        c.RESTORED_TIME < to_date(?,'mm/dd/yyyy hh24:mi:ss')
       )
于 2013-11-16T11:53:50.927 回答