在Mysql中创建存储过程,其中包含BLOB变量

发布于 2024-12-23 09:26:17 字数 1379 浏览 0 评论 0原文

这是适用于早期版本的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神经暖 2024-12-30 09:26:17

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文