How do you efficiently use OracleCommand and Parameters to get data from an Oracle DB when you have a fixed length char colum and don`t know how big the column is?
Let`s assume we want to get an ID named IID which is a char (5 bytes) fixed.
OracleCommand myCommand1;
myCommand1.CommandText = "SELECT * FROM IDS WHERE IID = :IID";
myCommand1.Parameters.AddWithValue("IID", "1234");
Would NOT return an item but
myCommand1.Parameters.AddWithValue("IID", "1234 ");
Would because it matches the 5 bytes in the database
You could also specify the space
myCommand1.Parameters.Add("IID", OracleDbType.Char, 5).Value = "1234";
But in my case just pretend that the programmer does not always know the exact amount of the char size defined in the database (if it makes sense or not). I use devart but I think this is more of a general issue. How could you pass the "1234" parameter without padding?
Thanks in advance
From the Data Type Comparison Rules documentation:
If you have two
CHARvalues then Oracle should use Blank-Padded Comparison Semantics and will add blanks to the strings until they are equal length.If you have one-or-more
VARCHAR2values then Oracle will use Non-Padded Comparison Semantics.This means you should be able to pass a
CHARof any length and it will be compared at the appropriate length:Note: If you are having this problem then it suggests that you should not be storing strings as a
CHARand should be usingVARCHAR2instead.