Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: SELECT DISTINCT Fails with Microsoft ODBC for Oracle


View products that this article applies to.

Symptoms

When a SELECT DISTINCT statement is used with the Microsoft ODBC for Oracle driver, the following error may occur:
DIAG [HYC00] [Microsoft][ODBC driver for Oracle]Cannot use Keyset-driven cursor on join, with distinct clause, union, intersect or minus or on read only result set (0)

↑ Back to the top


Cause

The Microsoft ODBC for Oracle driver uses the hidden Oracle column ROWID, which assigns a unique ID for each row. Because this negates the uniqueness constraint imposed by the DISTINCT keyword, the driver issues the above error rather than bring back multiple copies of the same data.

↑ Back to the top


Resolution

If you require the use of the DISTINCT keyword, you can use the Microsoft OLE DB Provider for Oracle, because the provider doesn't use the ROWID column when DISTINCT is used. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
258997 INFO: Oracle OLE DB Provider and ROWID Use
There is no workaround for this behavior with the Microsoft ODBC for Oracle driver.

↑ Back to the top


More information

Steps to Reproduce Behavior

  1. Create a table to test with:
    CREATE TABLE FOO (C1 CHAR(20))
    						
  2. Insert some data into the table:
    INSERT INTO FOO VALUES('aaa')
    INSERT INTO FOO VALUES('bbb')
    						
  3. Using the ODBC API SQLSetConnectAttr, set the connection attribute SQL_CURSOR_TYPE to the value SQL_CURSOR_KEYSET_DRIVEN. This ensures that you get a keyset cursor, which uses the hidden ROWID column.
  4. Execute the following SQL statement:
    SELECT DISTINCT * FROM FOO
    						
The ODBC call returns SQL_ERROR, and the associated error text will be the error shown in the "Symptoms" section of this article.

↑ Back to the top


Keywords: KB277667, kbprb, kboracle

↑ Back to the top

Article Info
Article ID : 277667
Revision : 5
Created on : 12/5/2003
Published on : 12/5/2003
Exists online : False
Views : 333