简体   繁体   中英

SQL Server 2008 JOIN with Oracle 11g

I have successfully linked an Oracle 11g database to SQL Server 2008. I can run a simple query in SQL Server which displays Oracle data:

SELECT PRODUCT_CODE
FROM [ORACLE-LINK]..ORACLE_SCHEMA.PRODUCTS_TABLE

This does exactly what I would expect it to do.

The problem comes when I try to do a simple join:

SELECT ProductName, [ORACLE-LINK]..ORACLE_SCHEMA.PRODUCTS_TABLE.PRODUCT_NAME
FROM SqlServer_table
INNER JOIN [ORACLE-LINK]..ORACLE_SCHEMA.PRODUCTS_TABLE
ON SqlServer_table.Product_ID=[ORACLE-LINK]..ORACLE_SCHEMA.PRODUCTS_TABLE.PRODUCT_CODE

This causes a 'The multi-part identifier could not be bound' error on the Oracle part of the JOIN statement. I know from research that the syntax has to be exact, and I think I've tried almost every permutation. Perhaps there's something in the SQL Server settings/registry...

Following @shiva's helpful suggestion I reformatted the query with aliases. This threw a server collation mismatch error, which proved much more illuminating than the 'The multi-part identifier' message I had been getting earlier. It turns out the joined columns had different collations (SQL_Latin1_General_CP1_CI_AS vs Latin1_General_CI_AS). Adding a simple COLLATE to the end of the JOIN AS part of the query sorted this out.

Have you tried alias-ing the table names? Like so

SELECT SqlSvr.ProductName AS Sql_ProductName
    , Orcl.PRODUCT_NAME AS Orcl_ProductName
FROM SqlServer_table AS SqlSvr
  INNER JOIN [ORACLE-LINK]..ORACLE_SCHEMA.PRODUCTS_TABLE AS Orcl
  ON SqlSvr.Product_ID = Orcl.PRODUCT_CODE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM