在Mysql中创建存储过程,其中包含BLOB变量
这是适用于早期版本的 mysql 的存储过程。现在,我有 Mysql 5.5.19.0,我无法创建如下所示的存储过程,
DELIMITER $$
USE `XXX`$$
DROP PROCEDURE IF EXISTS `current_to_prev`$$
CREATE DEFINER=`user`@`localhost` PROCEDURE `current_to_prev`(
IN _USERNAME VARCHAR(45),
IN _FILENAME VARCHAR(45),
IN _TYPE INT
)
BEGIN
DECLARE _uid INT;
DECLARE _fdata BLOB;
DECLARE _fname VARCHAR(45);
DECLARE _type VARCHAR(45);
SET _uid = (SELECT userid FROM USER WHERE username = _USERNAME);
SET _fdata = (SELECT FileData FROM userfiles_current WHERE userid = _uid AND filename = _FILENAME);
SET _fname = (SELECT FileName FROM userfiles_current WHERE userid = _uid AND filename = _FILENAME);
SET _type = (SELECT TYPE FROM userfiles_current WHERE userid = _uid AND TYPE = _TYPE);
UPDATE userfiles_prev SET FileData = _fdata, FileName = _fname, TYPE = _type WHERE userid = _uid AND filename = _FILENAME;
END$$
DELIMITER ;
我收到以下错误:
Query : CREATE DEFINER=
user
@localhost
PROCEDURE current_to_prev
( IN _USERNAME VARCHAR(45), IN _FILENAME VARCHAR(45), IN _TYPE INT ...
错误代码:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 '_FILENAME VARCHAR(45), 附近使用的正确语法 IN _TYPE INT ) 开始 声明 _uid INT; 在第 3 行声明 _fdata B' 正如
你所看到的,MySQL 不能接受 BLOB 变量。我该如何解决这个问题?
提前致谢!
This is stored procedure that worked on earlier version of mysql. Now, I have Mysql 5.5.19.0 and I can not create stored procedure that look like this
DELIMITER $
USE `XXX`$
DROP PROCEDURE IF EXISTS `current_to_prev`$
CREATE DEFINER=`user`@`localhost` PROCEDURE `current_to_prev`(
IN _USERNAME VARCHAR(45),
IN _FILENAME VARCHAR(45),
IN _TYPE INT
)
BEGIN
DECLARE _uid INT;
DECLARE _fdata BLOB;
DECLARE _fname VARCHAR(45);
DECLARE _type VARCHAR(45);
SET _uid = (SELECT userid FROM USER WHERE username = _USERNAME);
SET _fdata = (SELECT FileData FROM userfiles_current WHERE userid = _uid AND filename = _FILENAME);
SET _fname = (SELECT FileName FROM userfiles_current WHERE userid = _uid AND filename = _FILENAME);
SET _type = (SELECT TYPE FROM userfiles_current WHERE userid = _uid AND TYPE = _TYPE);
UPDATE userfiles_prev SET FileData = _fdata, FileName = _fname, TYPE = _type WHERE userid = _uid AND filename = _FILENAME;
END$
DELIMITER ;
I receive following error:
Query : CREATE DEFINER=
user
@localhost
PROCEDURE current_to_prev
( IN _USERNAME VARCHAR(45), IN _FILENAME VARCHAR(45), IN _TYPE INT ...
Error Code : 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 '_FILENAME VARCHAR(45),
IN _TYPE INT
)
BEGIN
DECLARE _uid INT;
DECLARE _fdata B' at line 3
As you can see MySQL can not accept BLOB variable. How can I solve this problem?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MySQL 接受 blob 等类型的参数、变量等。
参数
IN _FILENAME
中的错误 - 它是MySQL accepts params, variables and so on with type like blob.
The error in parameter
IN _FILENAME
- it is the reserved word. Change it something else and you will be fine.