Encountered when using case when in mybatis for condition filtering judgment
Failed to process, please exclude the tableName or statementId.
Such error messages are syntax errors
but I have no problem running SQL statements on the MySQL command line
//case when
WHERE dept.type = 1
AND
(
CASE agent.dept_type
WHEN "agent" THEN dept.id=30
END
)
//When the agent's dept_type is "agent", the judgment that dept.id = 30 will be added
There is no problem running this SQL statement on the command line, but an error will be reported if it is executed on mybatis
//Modified
WHERE dept.type = 1
AND dept.id=
(
CASE agent.dept_type
WHEN "agent" THEN 30
END
)
Later, put dept.id outside to solve this problem
20190718 – Supplementary record: another problem is encountered. If the dept
table is associated query, there may be no data. When the dept
has no data, we can’t assign any parameters to dept.id
and can’t affect the query of the data in the original table. I changed it to the following:
//Modified
WHERE dept.type = 1
AND (dept.id=
(
CASE agent.dept_type
WHEN "agent" THEN 30
ELSE 0
END
) or dept.id is null)
Add the judgment that dept.id
is empty
(there are many ways to solve it in MySQL statements, but an error will be reported on mybatis – – |)
2019-7-30-supplementary notes:
if it is an empty string, you can’t use ""
but change it to single quotation mark ''
CASE WHEN *** THEN ***
ELSE "" =>Need to change to=> ELSE''
Read More:
- [Solved] Mybatis.generator error: Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2
- [Solved] mybatis plus Insert Error: mybatis plus Error setting null for parameter #1 with JdbcType OTHER
- [Solved] Mybatis Error: Could not find resource mybatis-conf.xml
- [Solved] Tk-Mybatis Error: tk.mybatis.mapper.MapperException:
- Mybatis Error: Error instantiating class bakou.entity.Person with invalid types () or value)
- [Solved] Heroku Error: Web process failed to bind to $PORT within 60 seconds of launch
- How to Solve SQL comments error in the mybatis query
- Android studio compilation failed: java.util.concurrent.ExecutionException: com.android.ide.common.process.Process
- Code case of XXL job executor
- C++ String case conversion and transform, tower, upper, usage
- Mybatis single parameter pass in exception (How to Fix)
- How to Solve mybatis-plus Paging Plug-in PaginationInnerInterceptor error
- Java callback function implementation case
- mybatis Error: All elements are null [How to Solve]
- [Solved] In case of “transactionmanager” while setting bean property “transactionmanager” error
- [Solved] Mybatis Error: attempting to get column ‘XX’ from result set
- Mybatis plus configuration console prints complete SQL statement with parameters
- [Solved] Mybatis insert Error: Cause: java.sql.SQLException: SQL String cannot be empty
- How to Solve Mybatis error: invalid bound statement (not found)
- Using mybatis statement.getGenreatedKeys(); usegeneratedkeys = “true”; using self incrementing primary key to get primary key value policy and Oracle do not support self incrementing, Oracle uses sequence