【问题标题】:MYSQL insert statement wont work. Error 1064 Syntax [duplicate]MYSQL 插入语句将不起作用。错误 1064 语法 [重复]
【发布时间】:2016-02-09 15:33:53
【问题描述】:

这是我的代码:

INSERT INTO aggregate_summary (sampler_label,aggregate_report_count,average,aggr
egate_report_median,aggregate_report_90%_line,aggregate_report_min,aggregate_rep
ort_max,aggregate_report_error%,aggregate_report_rate,aggregate_report_bandwidth
,aggregate_report_stddev) VALUES ("2010 sf1","238","276","16","224","2","3121","
0.0","55.04162812210916","249.6223837881591","766.5325177049589"), ("TOTAL","238
","276","16","224","2","3121","0.0","55.04162812210916","249.6223837881591","766
.5325177049589")

我收到此错误:

ERROR 1064 (42000):您的 SQL 语法有错误;检查 与您的 MySQL 服务器版本相对应的手册 在 'egate 附近使用的语法 _report_median,"aggregate_report_90%_line",aggregate_report_min,aggregate_r' 在第 1 行

谁能帮我找出问题谢谢!

【问题讨论】:

  • 标识符无效,在 aggregate_report_90%_line 等周围使用反引号
  • 根据您的问题判断,您的代码已被证明为 80 列并带有硬换行符...
  • % 是数学模运算符,因此您的字段名称是完全非法的。
  • 您不能在标识符中间放置空格(例如回车)。这使它成为 两个 标识符,它们都不存在。将您的代码格式化为人类可读的,作为奖励,查询解析器将更容易理解它。

标签: mysql sql mysql-error-1064


【解决方案1】:

您必须将任何带有空格或标点符号(如百分号)的列名放在反引号中。

INSERT INTO foo ( `some column`, `other column %`, ...

【讨论】:

    【解决方案2】:

    您需要通过将列放在 ` 字符之间来定义列,因为其中一些列使用 reserved words 用于 mysql,例如您的名为 average 的列

    INSERT INTO aggregate_summary (sampler_label,aggregate_report_count,`average`,`aggr
    egate_report_median`,`aggregate_report_90%_line`,aggregate_report_min,aggregate_rep
    ort_max,aggregate_report_error%,aggregate_report_rate,aggregate_report_bandwidth
    ,aggregate_report_stddev) VALUES ("2010 sf1","238","276","16","224","2","3121","
    0.0","55.04162812210916","249.6223837881591","766.5325177049589"), ("TOTAL","238
    ","276","16","224","2","3121","0.0","55.04162812210916","249.6223837881591","766
    .5325177049589")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-10
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      • 2015-04-22
      相关资源
      最近更新 更多