Home  >  Article  >  Database  >  Why does invalid column index appear in sql

Why does invalid column index appear in sql

coldplay.xixi
coldplay.xixiOriginal
2020-08-22 10:07:066136browse

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.

Why does invalid column index appear in sql

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn