zoukankan      html  css  js  c++  java
  • JSqlParser解析SQL时SUM包裹IF出错

    SQL

    SELECT SUM(IF(1=1,1,0)) AS `result` FROM sys_user
    

    这种会报错的。

    错误信息

    Caused by: net.sf.jsqlparser.JSQLParserException: null
    at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatements(CCJSqlParserUtil.java:154)
    at com.baomidou.mybatisplus.core.parser.AbstractJsqlParser.parser(AbstractJsqlParser.java:64)
    ... 92 common frames omitted
    Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "(" "("
    at line 10, column 19.

    Was expecting one of:
    "&"
    ","
    "::"
    ";"
    "<<"
    ">>"
    "ACTION"
    "ANY"
    "AS"
    "BYTE"
    "CASCADE"
    "CAST"
    "CHAR"
    "COLUMN"
    "COMMIT"
    "CONNECT"
    "DO"
    "ENABLE"
    "END"
    "EXCEPT"
    "EXTRACT"
    "FIRST"
    "FOLLOWING"
    "FOR"
    "FROM"
    "GROUP"
    "HAVING"
    "INDEX"
    "INSERT"
    "INTERSECT"
    "INTERVAL"
    "INTO"
    "ISNULL"
    "KEY"
    "LAST"
    "MATERIALIZED"
    "MINUS"
    "NO"
    "NULLS"
    "OPEN"
    "ORDER"
    "OVER"
    "PARTITION"
    "PERCENT"
    "PRECISION"
    "PRIMARY"
    "PRIOR"
    "RANGE"
    "REPLACE"
    "ROW"
    "ROWS"
    "SEPARATOR"
    "SIBLINGS"
    "START"
    "TABLE"
    "TEMP"
    "TEMPORARY"
    "TRUNCATE"
    "UNION"
    "UNSIGNED"
    "VALUE"
    "VALUES"
    "WHERE"
    "XML"
    "ZONE"
    "^"
    "|"

    <K_DATETIMELITERAL>
    <S_CHAR_LITERAL>
    <S_IDENTIFIER>
    <S_QUOTED_IDENTIFIER>
    at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:18597)
    at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:18447)
    at net.sf.jsqlparser.parser.CCJSqlParser.Statements(CCJSqlParser.java:516)
    at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatements(CCJSqlParserUtil.java:152)
    ... 93 common frames omitted

    解决办法

    将IF换成case when的形式

  • 相关阅读:
    VUE 源码工具
    elasticsearch 根据主键_id更新部分字段
    Linux下解压文件到其他目录
    centos 7 安装docker
    英语阅读
    将Word文件上传到博客园
    kafka
    ubantu批量下载依赖包+apt命令list
    llvm.20.SwiftCompiler.Compiler-Driver
    Java获取resources文件夹下properties配置文件
  • 原文地址:https://www.cnblogs.com/daihang2366/p/15382788.html
Copyright © 2011-2022 走看看