Reasons for invalid column index in sql: 1. The placeholder is inconsistent with the number of parameters; 2. SQL splicing error, please note that each [%] must be included with [''], and with the parameters, use [ ||] splicing; 3. Wrong annotation.
【Related learning recommendations: SQL video tutorial】
Reason for invalid column index in sql:
It is basically certain that this error is generally caused by low-level mistakes. Please check your sql spelling
Follow the online instructions I looked for the problem pointed out and found that there was no error that was the same as my own. Finally, after removing a comment, it became normal.
I used idea and used ctrl / to add the comment, that is, add -- before sql.
I don’t know why it didn’t take effect, but it became the source of the error.
Record it here to prevent yourself from forgetting. Several other possible spelling errors are as follows
1 .The placeholder is inconsistent with the number of parameters
For example, when there is a placeholder? , but two parameters #{a},#{b} are passed in here,
2.sql splicing error
For example, for fuzzy query condition a Splicing
a like '%'||#{a}||'%'
Note that each % must be enclosed with '', and spliced with parameters using ||
Of course you can also write a like CONCAT(CONCAT('%', #{a}), '%')
3. Wrong comment
This is the situation I encountered. I commented out the unused sql through --,
but the comments did not take effect normally, resulting in invalid column indexes. Delete them and it will be fine.
Of course there may be other reasons for this situation
For more SQL technical articles, please visit the php Chinese websiteSQL database technical articleschannel.
The above is the detailed content of Why does invalid column index appear in sql. For more information, please follow other related articles on the PHP Chinese website!