ORACLE ORA00907:在OraClient10g_home3中使用OraOLEDB.Oracle与Oracle通过Oracle进行TNS查找的连接字符串的差异

时间:2014-07-30 00:54:07

标签: sql oracle excel-vba connection-string ora-00907

我正在使用Oracle Client 10.2g,并且通过将我的连接字符串更改为Oracle数据库,现在我的一些查询出现错误ORA00907。

代码在excel 2010中使用VBA执行,我可以使用以下连接字符串运行20+ quire而不会出错:

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;"

20个查询中有2个查询因ORA-00907而失败:缺少右括号

其中一个失败(折射)的查询:

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;

我已经测试过Query在Oracle SQL Developer中正确运行。 我已经验证,在执行查询之前,两个连接字符串的SQL语句都是相同的。

另一个失败的查询也使用了union和rank函数,但它不是唯一的。

我希望使用OraOLEDB.Oracle连接的原因是我试图删除我对tnsnames.ora文件的依赖,因为我不时添加新的数据库实例并希望避免所有用户都必须更新此文件在oracle目录中。

最后,ORACLE数据库是版本8.

非常感谢任何帮助,

提前致谢!

更新:删除了拼写错误

1 个答案:

答案 0 :(得分:0)

好的,我已经解决了。

感谢那些花时间思考它的人。

当我折射上面的示例时,我删除了由&#39; - &#39;表示的内联注释。 正是这些注释导致OraOLEDB.Oracle驱动程序出现ORA-00907错误。

所以修复很简单:从SQL命令中删除注释!

再次感谢!