create triggers - error at DECLARE(创建触发器 - DECLARE 时出错)
本文介绍了创建触发器 - DECLARE 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从 http://forge.mysql.com/wiki/Triggers 学习触发器我有:
i learn triggers from http://forge.mysql.com/wiki/Triggers and i have:
create trigger bi_emps_fer before insert on emps for each row
begin
declare newsal numeric default 0;
declare namelength, l_loop int default 0;
set namelength = length(new.emp_name);
while l_loop < namelength do
set newsal := newsal new.salary;
set l_loop := l_loop 1;
end while;
set new.salary = newsal;
end
和错误:
1064 - 您的 SQL 语法有错误;检查手册对应于您的 MySQL 服务器使用正确语法的版本在第 4 行的 '' 附近
1064 - 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 '' at line 4
为什么?我使用 MySQL 5.5.8 和 phpmyadmin 3.3.9
why? i use MySQL 5.5.8 and phpmyadmin 3.3.9
推荐答案
您是否指定了分隔符?
delimiter #
create trigger bi_emps_fer before insert on emps for each row
begin
declare newsal decimal(10,2) default 0;
// do sql stuff here but not what you're doing !
set new.salary = newsal;
end#
delimiter ;
这篇关于创建触发器 - DECLARE 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:创建触发器 - DECLARE 时出错


基础教程推荐
猜你喜欢
- oracle区分大小写的原因? 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 在多列上分布任意行 2021-01-01