ORACLE ORA00907: Differences in connection string using OraOLEDB.Oracle vs TNS lookup via Oracle in OraClient10g_home3

StackOverflow https://stackoverflow.com//questions/25027232

Question

I am using Oracle Client 10.2g and by changing my connection string to the Oracle database I now get error ORA00907 for some of my queries.

The code is executing within excel 2010 using VBA and I can run 20+ quires without error using the following connection string:

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

By changing the connection string only to:

ServerConnectionString="Provider=OraOLEDB.Oracle;Data Source=(<<<data exact translation from TNSNAMES file for the DBNAME>>>);User id=USERNAME;Password=PASSWORD;"

2 of the 20+ queries fail with ORA-00907: missing right parenthesis

One of the Queries that fails (refracted):

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;

I have tested that the Query runs correctly in Oracle SQL Developer. I have verified that prior to Executing the query the SQL statements are identical for both connection strings.

The other query that fails is also using a union and rank function but it is not the only one.

The reason I wish to use the OraOLEDB.Oracle connection is that I am attempting to remove my reliance on the tnsnames.ora files as from time to time I add new database instances and want to avoid all my users having to update this file in the oracle directory.

Lastly the ORACLE database is version 8.

Any help would be greatly appreciated,

Thanks in advance!

Updated: Removed typo error

Was it helpful?

Solution

OK I've work it out.

Thanks to all those that spent any time thinking about it.

When I refracted the example above I removed inline comments denoted by '--'. It was these comments that caused the ORA-00907 error with the OraOLEDB.Oracle driver.

So the fix is simple: Remove comments from the SQL command!

Thanks again!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top