我有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
由于
答案 0 :(得分:0)
错误是关于日期格式,而不是关于联合
如果将单元格值作为字符串参数传递,Oracle会尝试将其转换为日期,以使用表列中的date
或timestamp
列的列进行comapre。要执行此转换,Oracle会在您的情况下使用它的内部默认date representation format,而不是mm/dd/yyyy hh24:mi:ss
。
有两种可能来解决问题:
传递date
类型的参数,以便在将值传递给Oracle之前查询并将值转换为日期。查看examples on MSDN以及CreateParameter和Parameters.Append方法的说明。
使用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')
)