oracle - Different matches when using prepared statements on CHAR(3) column -


I wanted to enlarge a CHAR (1 CHAR) column and I forgot to change the column VARCHAR2 to type:

  duplikode char (3 years)  

I got an error when my PHP app is no longer Exact match matching example:

  SELECT * NUMEROS WHERE DUPLICADO =: foo  

... with : foo Getting # 4 3-Four Padded Not Found # 4 However, I initially hit a red herring while debugging the query in SQL Developers because the raw values ​​in the query will match the injection!

  SELECT * FROM NUMEROS WHERE DUPLICADO = '# 4'  

Why do I get mail from another query? Why does it make a difference in prepared statements?

To make a little detail on my observations, I found a little documentation which is empty and non-platen Explains the difference between the comparison of:

If there are both values ​​in your comparison (both sides of the equals sign), if the data are CHAR or NCHAR or literal string Oracle chooses empty eyelid comparison. This means that if the length is different, then it pad at least one of the spaces until they are not the same length.

Column DUPLICADO to be CHAR (3) , value '# 4' in the form of three letters in the column '# 4' (Note the blank as the third letter.) When you do, DUPLICADO = '# 4' rules state Oracle Blank Pethal Use the comparison and therefore Colapad literally does not have the same length as the column '# 4' . So it actually becomes DUPLICADO = '# 4' .

But when you do DUPLICADO =: foo , then it will depend on the bind datatype variable If the datatype is CHAR, then it will also compare the empty plaque. But if the datatype is VARCHAR2, then Oracle will use a non-padded comparison and then it will depend on you to make blank bars where necessary.

Depending on the client or the client language, you can specify the datatype of the bind variable and thus get an empty plat or nonpaid comparison as needed.

The SQL developer may be a special case that does not allow you to specify the datatype - it can only possibly be redirected to VARCHAR2. I do not know enough about SQL Developers; -)


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -