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:
- Mybatis reports an error (error building sqlsession.) when using annotations without deleting redundant files
- Error querying database.Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource.
- [Solved] java.sql.SQLException: Unknown system variable cache query size
- 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
- [Solved] Cannot find class: com.mysql.jdbc.Driver
- How to Solve idea com.baomidou Error
- [Solved] Command line is too long. Shorten command line for XXXXXXXTest.rmLogRecordOver Error running
- Mybatis query error: Exception in thread “main” org.apache.ibatis.exceptions.PersistenceException…
- Mybatis plus configuration console prints complete SQL statement with parameters
- [Solved] Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException
- [Solved] Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration
- [Solved] Failed to configure a DataSource: ‘url‘ attribute is not specified…bug
- BigDecimal Error: NumberFormatException [How to Solve]
- [Solved] com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure error
- [Solved] mybatis Error querying database. Cause: java.sql.SQLException: The server time zone value
- [Solved] BindingException: Type interface XXX is not known to the MapperRegistry
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘testApplicat
- SpringBoot Project Run Page Error: Whitelabel Error Page This application has no explicit mapping for /error
- [Solved] ClickHouse Error: Code: 62. DB::Exception: Syntax error (Multi-statements are not allowed): fai