MySQL 查询语句错误

标签 mysql sql mysql-error-1064

我正在尝试熟悉 Mysql 语法。到目前为止我只使用过MSSQL。我下载了 MySQL 查询浏览器并安装了 MySQL 版本 5.1

我想在 MySQL 的结果集选项卡中运行这行代码,但我不断遇到以下错误

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'declare iCtr int' at line 1

代码:

declare iCtr int;
set iCtr = 1;

while iCtr < 1000
begin
    insert into employee (emp_id,emp_first_name,emp_last_name,status_id)
      values (iCtr, 'firstName' + iCtr, 'lastName' + iCtr, 1)
      set iCtr = iCtr + 1;
end

我只是想填充我的员工表,但我无法超越 MySQL 语法。

最佳答案

来自:http://dev.mysql.com/doc/refman/5.0/en/declare.html

DECLARE is permitted only inside a BEGIN ... END compound statement and must be at its start, before any other statements.

我认为这可能是麻烦所在?

关于MySQL 查询语句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4613153/

相关文章:

sql - 如何从数据库中删除几乎相同记录的连续序列

.net - 从微 Controller (带有 .Net Micro Framework 的 Arduino 或 Fez)连接到 SQL Server

database-connection - 如何在mysql服务器中连接我的本地ip

mysql - 格式化 11/16/2002 12 :00:00 PM to date time stamp in MySQL

mysql - 生成一个按月显示 Android 和 iOs 访问者的表格?数据库

mysql - SELECT by A列OR B列在数据库中的数据比较顺序是什么

Mysql2::错误:表不存在:显示来自 `sessions` 的完整字段

mysql - 仅选择一个等于 "z"的字段

MySQL "sending data"事件需要更长的时间

mysql - 配置mysql服务器安装失败或无法启动服务