"DELIMITER $$"附近出现错误 [英] Error near 'DELIMITER $$'

查看:132
本文介绍了"DELIMITER $$"附近出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从mysql控制台或MySQL Workbench更改Delimeter时,没有出现任何错误, 但是当我将相同的代码嵌入在ruby的rails上时,我得到了错误

when I change Delimeter from mysql console or MySQL Workbench I do not get any error, but when I embed the same code in ruby on rails I get error

mysql> DELIMITER $$
mysql>

没有错误.

但是

ActiveRecord::Base.connection.execute(%Q{
    DELIMITER $$
})

给予:

ActiveRecord::StatementInvalid: Mysql2::Error: 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 'DELIMITER $$' at line 1: 

推荐答案

DELIMITER实际上是MySQL命令行设置,而不是SQL:

DELIMITER is actually a MySQL command line setting, not SQL: http://dev.mysql.com/doc/refman/5.0/en/mysql-commands.html. That means that you can't set the delimiter in this way.

最重要的是,如果ActiveRecord::Base.connection.execute只允许您一次执行一条语句,这将无济于事(请参阅

On top of that, it wouldn't help if you could as ActiveRecord::Base.connection.execute only allows you to execute one statement at a time out of the box (see http://www.seanr.ca/tech/?p=75).

这篇关于"DELIMITER $$"附近出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆