mysql创建一个简单的过程

时间:2015-03-23 09:09:20

标签: mysql

我很困惑......为什么下面的代码失败了? MySQL 5.6。我想创建简单的程序来删除某些表中的数据

DROP PROCEDURE IF EXISTS truncateStaging;
create procedure truncateStaging
begin
  delete from stg_user;
  delete from stg_userflag;
end;        
PROCEDURE test.truncateStaging does not exist
procedure IF dropped.    
Error starting at line : 3 in command -
create procedure truncateStaging
begin
  delete from stg_user;
  delete from stg_userflag;
end;
Error report -
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 'begin
  delete from stg_user;
  delete from stg_userflag;
end' at line 2

1 个答案:

答案 0 :(得分:1)

首先你需要更改分隔符,然后你忘记了程序定义中的()

DROP PROCEDURE IF EXISTS truncateStaging;
delimiter |
create procedure truncateStaging()
begin
  delete from stg_user;
  delete from stg_userflag;
end
|
delimiter ;