navicat不能创建函数
2017-01-20 10:45
435 查看
第一次写MySQL FUNCTION,一直报错,
Err] 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 '`company_id` int) RETURNS varchar(20) CHARSET utf8
BEGIN
本来的函数:
CREATE DEFINER=`33323`@`%` FUNCTION `createSaleCode`(`benginStr` varchar,`company_id` int) RETURNS varchar(20) CHARSET utf8
BEGIN
DECLARE nearnum VARCHAR(20);
DECLARE nowdatepre VARCHAR(20);
DECLARE numout VARCHAR(20);
SELECT a.sale_code INTO nearnum FROM d_sale a WHERE a.company_id = company_id ORDER BY a.sale_id DESC limit 1;
SELECT concat(extract(year_month from now()),LPAD(extract(day from now()), 2, 0)) INTO nowdatepre;
IF locate(nowdatepre,nearnum)>0
THEN
set numout = nearnum +1;
ELSE
set numout = concat(beginStr,nowdatepre,'00001');
END IF;
RETURN numout;
END
这段函数在Navicat上边执行不起来,在多次尝试之后将代码修改为以下:
delimiter $$
CREATE DEFINER=`12212`@`%` FUNCTION createSaleCode(benginStr varchar(20),company_id int(11) ) RETURNS varchar(20) CHARSET utf8
BEGIN
DECLARE nearnum VARCHAR(20);
DECLARE nowdatepre VARCHAR(20);
DECLARE numout VARCHAR(20);
SELECT a.sale_code INTO nearnum FROM d_sale a WHERE a.company_id = company_id ORDER BY a.sale_id DESC limit 1;
SELECT concat(extract(year_month from now()),LPAD(extract(day from now()), 2, 0)) INTO nowdatepre;
IF locate(nowdatepre,nearnum)>0
THEN
set numout = nearnum +1;
ELSE
set numout = concat(beginStr,nowdatepre,'00001');
END IF;
RETURN numout;
END$$
delimiter ;
问题解决。
默认情况下,delimiter是分号;。
Err] 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 '`company_id` int) RETURNS varchar(20) CHARSET utf8
BEGIN
本来的函数:
CREATE DEFINER=`33323`@`%` FUNCTION `createSaleCode`(`benginStr` varchar,`company_id` int) RETURNS varchar(20) CHARSET utf8
BEGIN
DECLARE nearnum VARCHAR(20);
DECLARE nowdatepre VARCHAR(20);
DECLARE numout VARCHAR(20);
SELECT a.sale_code INTO nearnum FROM d_sale a WHERE a.company_id = company_id ORDER BY a.sale_id DESC limit 1;
SELECT concat(extract(year_month from now()),LPAD(extract(day from now()), 2, 0)) INTO nowdatepre;
IF locate(nowdatepre,nearnum)>0
THEN
set numout = nearnum +1;
ELSE
set numout = concat(beginStr,nowdatepre,'00001');
END IF;
RETURN numout;
END
这段函数在Navicat上边执行不起来,在多次尝试之后将代码修改为以下:
delimiter $$
CREATE DEFINER=`12212`@`%` FUNCTION createSaleCode(benginStr varchar(20),company_id int(11) ) RETURNS varchar(20) CHARSET utf8
BEGIN
DECLARE nearnum VARCHAR(20);
DECLARE nowdatepre VARCHAR(20);
DECLARE numout VARCHAR(20);
SELECT a.sale_code INTO nearnum FROM d_sale a WHERE a.company_id = company_id ORDER BY a.sale_id DESC limit 1;
SELECT concat(extract(year_month from now()),LPAD(extract(day from now()), 2, 0)) INTO nowdatepre;
IF locate(nowdatepre,nearnum)>0
THEN
set numout = nearnum +1;
ELSE
set numout = concat(beginStr,nowdatepre,'00001');
END IF;
RETURN numout;
END$$
delimiter ;
问题解决。
默认情况下,delimiter是分号;。
相关文章推荐
- 深入理解PowerManagerService
- rece_2
- EL表达式截取字符串
- java中获取当前日期和时间的方法
- PHP7.1新特性一览
- 安装ipython时python setup.py egg_info错误的解决办法
- 2017寒假阅读笔记01
- Python基础学习笔记
- Docker安装和简单使用入门教程
- TCP、UDP、IP 协议分析
- 嵌入式培训的骗局这些事你怎么看?
- 【Android】AlertDialog中的EditText不能弹出软键盘的问题
- adb devices offline solution for Window Batch CMD
- hive常用查询
- C语言再学习 -- 详解C++/C 面试题 1
- mars C层消息发送流程
- iOS-父视图半透明子alpha视图不透明
- can't open /dev/ttyS0: No such file or directory
- Android基础—Handler消息机制
- JSON的基本结构和数据交换原理