使用Microsoft Excel 2007通过ODBC驱动程序查询Oracle Datawarehouse

时间:2016-02-15 15:27:08

标签: excel oracle

我正在尝试将两个日期参数传递给Microsoft Excel中的查询。

当命令文本如下时,查询完全正常:

SELECT TINVOICE.INV_DINVOICEDATE, TINVOICEDETAIL.IDE_SCATEGORY,
       TINVOICETEMPLATEFIELDCATEGORY.IFC_SDESCRIPTION,
       TINVOICE.INV_CUS_LKEY, TCUSTOMER.CUS_SNUMBER,        
       TCUSTOMER.CUS_SNAME, TINVOICE.INV_LNUMBER, 
       TINVOICE.INV_AGR_LKEY, TINVOICEDETAIL.IDE_FLINETOTAL

FROM PROD.TCUSTOMER TCUSTOMER, PROD.TINVOICE TINVOICE, 
     PROD.TINVOICEDETAIL TINVOICEDETAIL, 
     PROD.TINVOICETEMPLATEFIELDCATEGORY TINVOICETEMPLATEFIELDCATEGORY

WHERE TCUSTOMER.CUS_LKEY = TINVOICE.INV_CUS_LKEY 
  AND TINVOICE.INV_LKEY = TINVOICEDETAIL.IDE_INV_LKEY 
  AND TINVOICEDETAIL.IDE_SCATEGORY = TINVOICETEMPLATEFIELDCATEGORY.IFC_SCODE 
  AND ((TINVOICE.INV_DINVOICEDATE>= {ts '2015-02-01 00:00:00'}) 
  AND (TINVOICE.INV_DINVOICEDATE< {ts '2016-02-01 00:00:00'}) 
  AND (TINVOICEDETAIL.IDE_SCATEGORY<>'GS28') 
  AND (TINVOICE.INV_LNUMBER<>0) 
  AND (TINVOICEDETAIL.IDE_FLINETOTAL<>0))
ORDER BY TINVOICE.INV_LNUMBER

但是当我通过交换这些块{ts'2015-02-01 00:00:00'}来降低参数时,这些'?'它会抛出一个错误。我玩了很多解决方案,但似乎都没有,或者我没有正确实现它们。当我查询数据库NLS属性时,它返回以下内容:

PARAMETER                VALUE
NLS_LANGUAGE             ENGLISH
NLS_TERRITORY            UNITED KINGDOM
NLS_CURRENCY             £
NLS_ISO_CURRENCY         UNITED KINGDOM
NLS_NUMERIC_CHARACTERS   .,
NLS_CALENDAR             GREGORIAN
NLS_DATE_FORMAT          DD-MON-RR
NLS_DATE_LANGUAGE        ENGLISH
NLS_SORT                 BINARY
NLS_TIME_FORMAT          HH24.MI.SSXFF
NLS_TIMESTAMP_FORMAT     DD-MON-RR HH24.MI.SSXFF
NLS_TIME_TZ_FORMAT       HH24.MI.SSXFF TZR
NLS_TIMESTAMP_TZ_FORMAT  DD-MON-RR HH24.MI.SSXFF TZR
NLS_DUAL_CURRENCY        €
NLS_COMP                 BINARY
NLS_LENGTH_SEMANTICS     BYTE
NLS_NCHAR_CONV_EXCP      FALSE

如果有人可以提供帮助,我会非常感激!并且如果需要可以提供更多信息!

谢谢!

1 个答案:

答案 0 :(得分:1)

这里只是猜测,但{ts}构造特定于ODBC / JDBC,因此将它与本机oracle中的变量绑定混合可能导致问题。为什么不尝试将其替换为Oracle的本机to_timestamp函数呢?

 AND ((TINVOICE.INV_DINVOICEDATE>= to_timestamp(?,'YYYY-mm-dd HH24:MI:SS') ) 
  AND (TINVOICE.INV_DINVOICEDATE< to_timestamp(?,'YYYY-mm-dd HH24:MI:SS')) 

虽然也检查并确保该字段是时间戳而不是日期(您的格式化字符串中没有小数秒),在这种情况下,to_Date会更合适。