0

我在 MYSQL 中创建了以下 SP

CREATE PROCEDURE usp_BookDetailsCount(OUT bookCount INT)
BEGIN
       SELECT count(*) INTO bookCount 

       FROM books;

       SELECT bookCount;
END $$

我正在尝试使用 rails 3.2.8 获取 SP 输出参数值。

我在模型中的代码

count = 0 
 r = ActiveRecord::Base.connection.select_value("CALL usp_BookDetailsCount(OUT count)")   
 return count

我在浏览器中收到以下错误

Mysql::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 'OUT count)' at line 1: CALL usp_BookDetailsCount(OUT count)

但是我可以在没有 OUT 参数的情况下获取存储过程值

4

1 回答 1

0

恐怕没有用于与存储过程交互的特定 AR API 方法。尝试#执行:

http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#method-i-execute

于 2012-10-15T07:54:01.037 回答