我使用Oracle Client 10.2g,通过改变我的连接字符串到Oracle数据库,我现在得到错误ORA00907为我的一些查询。
代码使用VBA在excel 2010中执行,我可以使用以下连接字符串运行20+查询而没有错误:
ServerConnectionString="Driver={Oracle in OraClient10g_home1};Dbq=DBNAME;Uid=USERNAME;Pwd=PASSWORD;"
With OpenR2DBConnection
.ConnectionTimeout = ConnectionTimeout
.Open ServerConnectionString
.Execute "ALTER SESSION SET NLS_DATE_FORMAT = 'DD/MM/YYYY'"
.CommandTimeout = CommandTimeout
End With
通过将连接字符串仅更改为:
ServerConnectionString="Provider=OraOLEDB.Oracle;Data Source=(<<<data exact translation from TNSNAMES file for the DBNAME>>>);User id=USERNAME;Password=PASSWORD;"
在ORA-00907中,20多个查询中有2个失败:缺少右括号
一个失败的查询(折射):
select n1.name,n1.sdate,n1.edate,n1.note as crnote,n1.cdate ,n1.pri
from
(
select n.name,n.sdate,n.edate,n.note,n.cdate,n.pri , RANK() OVER (PARTITION BY n.sdate,pri ORDER BY (n.adate - n.cdate) asc,n.pri asc) RANK
from
(
select mmpe.name,mmpe.sdate,mmpe.edate,mmpe.cannote as note,mmpe.cdate,mmip.crdate as adate,mp.pri
from mmpe ,mmmip mmip, mp
where <<clauses1>>
and mmpe.name in (<<list of strings>>)
and mmip.name(+) = mmpe.name
and <<more clauses2>>
union
Select mmip.name,mmip.sdate,greatest(<<formula>>) as edate , <<create note>> as note ,mmip.crdate as cdate, td.adate,mp.pri
From mi , mmip,td, mp
Where <<clauses3>>
and mi.name in (<<list of strings>>)
union all
Select mmip.name,mmip.sdate,mmip.edate as edate , <<create note>> as note ,mmip.crdate as cdate , td.adate,mp.pri
From mi , mmip,td, mp
Where <<clauses4>>
and mi.name in (<<list of strings>>)
union
Select mmip.name,mmip.sdate,td.cddate-1 as edate , <<create note>> as note, mmip.crdate as cdate,mmip.crdate as adate,mp.pri
From mi , mmip,td, mp
Where <<clauses4>>
and mi.name in (<<list of strings>>)
) n
) n1
where rank = 1
order by 6,2,5;
我已经测试了查询在Oracle SQL Developer中正确运行。在执行查询之前,我已经验证了两个连接字符串的SQL语句是相同的。
另一个失败的查询也使用了联合和排名函数,但它不是唯一一个。
我希望使用OraOLEDB的原因。Oracle连接是,我正试图消除我对名称的依赖。我不时地添加新的数据库实例,并希望避免所有用户必须更新oracle目录下的这个文件。
最后,ORACLE数据库是版本8。
任何帮助都将不胜感激,
提前感谢!
更新:删除了打字错误
好的,我算出来了。
感谢所有花时间思考这个问题的人。
当我引用上面的例子时,我删除了用'——'表示的内联注释。正是这些注释导致OraOLEDB出现ORA-00907错误。甲骨文司机。
所以修复很简单:从SQL命令中删除注释!
再次感谢!