This is a migrated thread and some comments may be shown as answers.

Generated comparison for Oracle CLOB column is incorrect

1 Answer 393 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Constantine
Top achievements
Rank 1
Constantine asked on 14 Oct 2014, 06:43 AM
Hi.

Case:
1. Use Oracle database.
2. Create table with CLOB column.
3. Write LINQ query to compare content of this column with string. For example, 'database.Users.Any(u => u.Email.ToUpper() == email.ToUpper());'.

Expected result:
Boolean value.

Real result:
Exception "Failure: Count(*) query failed: Telerik.OpenAccess.RT.sql.SQLException: ORA-00932: inconsistent datatypes: expected - got CLOB".

Reason:
TDA generated wrong SQL query 'SELECT COUNT(1) FROM ( SELECT a."Id" COL1, a."Email" COL2 FROM "Users" a WHERE upper(a."Email") = ?'. Right query is: 'SELECT COUNT(1) FROM ( SELECT a."Id" COL1, a."Email" COL2 FROM "Users" a WHERE DBMS_LOB.COMPARE(upper("Login"), ?) = 0'.

Question:
Will you change comparison generation for Oracle CLOB columns?





1 Answer, 1 is accepted

Sort by
0
Ralph Waldenmaier
Telerik team
answered on 14 Oct 2014, 09:25 AM
Hi Constantine,
The DBMS_LOB.COMPARE function call is necessary to ensure that CLOB types are compared correctly on the server. Unfortunately, in this situation the UPPER function call does not return the appropriate type to perform the operation correctly.

Though there is a way to fullfil your requirements by leveraging the .SQL LINQ extension. Please see this blog post for an example.

In your case it would look like this.
database.Users.Any(u => "UPPER({0}) = UPPER({1})".SQL<bool>(u.Email, email));

Please double check if the UPPER really meets your requirements because the documentation is not 100% clear if the same amount of data is returned as stored in the CLOB. This means, a CLOB can have a length bigger than 4000 chars. Probably the UPPER returns a max of 4000 chars.

I hope this information is helpful for you.
Do come back in case you need further assistance.


Regards,
Ralph Waldenmaier
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Data Access Free Edition
Asked by
Constantine
Top achievements
Rank 1
Answers by
Ralph Waldenmaier
Telerik team
Share this question
or