MySQL在执行代码时抛出错误

时间:2018-08-29 10:53:27

标签: mysql sql mysql-workbench

这是我的sql代码:

<form [formGroup]="registerForm" (ngSubmit)="onSubmit()">
  <div class="form-row">
     <div class="col">
        <label>First Name</label>
        <input type="text" class="form-control" placeholder="First name" formControlName="firstName" />
     </div>
     <div class="col">
       <label>Last Name</label>
       <input type="text" class="form-control" placeholder="Last name" formControlName="lastName" />
     </div>
  </div>
  <br>
  <div class="form-row">
        <div formArrayName="aliases">
          <button class="btn btn-info btn-sm" (click)="addAlias()">Add</button>
          <div *ngFor="let address of registerForm.controls.aliases.controls; let i=index">
            <div formGroupName="i">
                Name : <input type="text" class="form-control" formControlName = "Name" />
                Age : <input type="text" class="form-control" formControlName = "Age" />
            </div>
          </div>
        </div>
      </div>
      <br>
      <button type="submit" class="btn btn-primary">Submit</button>
</form>

SET @sql = NULL; SELECT GROUP_CONCAT(DISTINCT CONCAT( 'COALESCE(MAX(CASE WHEN delc = ''', delc, ''' then ''y'' end),''n'') AS ', delc ) ) INTO @sql FROM inputr; SET @sql = CONCAT('SELECT tem, ', @sql, ' FROM inputr GROUP BY tem'); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; 中执行此操作时,我得到mysql workbench 6.3

出了什么问题? 这是错误:

error code 1064

1 个答案:

答案 0 :(得分:0)

您的问题是由于最终查询的结构所致。我的猜测是delc的一个或多个值带有单引号或反斜杠。

最简单的解决方案是仅接受“正常”名称来消除这些问题

select . . .
from inputstr
where delc regexp '^[a-zA-Z0-9_]+$'

这些字符可以用作标识符和字符串,因此代码应该可以工作。