ORA-01425: escape character must be character string of length 1
The implementation of Contains()
method in LINQ with Entity Framework ODP seems not working properly when handling System.String
argument directly in certain situations, it will generate LIKE
with ESCAPE '\'
statement in PL/SQL query which will throw ORA-01425 error (as shown in similar issue here). To mitigate this behavior, just use Trim()
inside Contains()
method against string argument:
availableTasks.Where(task => task.Document.RegistrationNumber.Contains(searchkeyWord.Trim()) || task.WorkflowNumber.Contains(searchkeyWord.Trim()) || task.Description.Contains(searchkeyWord.Trim()));
The Trim()
method will generate INSTR
and TRIM
statements (or LTRIM
-RTRIM
pairs) as replacement of LIKE
with ESCAPE
statements, as in example below:
SELECT <snip> FROM <snip> WHERE [condition] AND ((NVL(INSTR("Filter1"."RegistrationNumber", TRIM(:p__linq__9)), 0)) > 0) OR ((NVL(INSTR("Filter1"."WorkflowNumber", TRIM(:p__linq__10)), 0)) > 0)OR ((NVL(INSTR("Filter1"."Description", TRIM(:p__linq__11)), 0)) > 0)
By implementing INSTR
with TRIM
, the query will run smoothly when handling LINQ generated parameters (:p__linq__XX
) containing System.String
value.
The ESCAPE
in the SQL statement you posted is fine - ESCAPE '\'
But this is the query text logged by LINQ
The best way to see the real query statement send to DB is to activate a 10046 trace.
ALTER SESSION SET tracefile_identifier = escape; alter session set events '10046 trace name context forever, level 12';
in your connection and run the statement.
You will find a file such as xxx_ora_NNNN_ESCAPE.trc in the trace folde of the DB Server.
I suspect you will see a statement using something like
escape '\\'
We had the same problem
Resolved by changing parameter CURSOR_SHARING
to EXACT