【问题标题】:i can not make aritmetic operation inside stored procedure mysql我无法在存储过程mysql中进行算术运算
【发布时间】:2017-09-13 13:30:55
【问题描述】:

有一个 in 参数作为页面。我想要做的就是从中驱逐 1 并乘以 10。但它每次都会给我一个错误。

IF !a THEN

  SELECT * 
  from entry 
  WHERE topic_foreign_id = ( 
    select topic_id 
    from topic 
    where topic_name = topicName
  )
  ORDER BY entry_time ASC 
  LIMIT 10 OFFSET page;

ELSE

  SELECT * 
  from entry
  WHERE topic_foreign_id = ( 
    select topic_id 
    from topic 
    where topic_name = topicName
  )
  ORDER BY entry_time ASC;

END IF

这行代码效果很好,但是当我想在第一个 SQL 查询中进行算术运算时,myAdmin 每次都会抛出错误。

SELECT * 
from entry 
WHERE topic_foreign_id = ( 
  select topic_id 
  from topic 
  where topic_name = topicName
) 
ORDER BY entry_time ASC 
LIMIT 10 OFFSET 10 * ( page - 1); //throws error

【问题讨论】:

标签: mysql sql stored-procedures


【解决方案1】:

--- 已编辑 ---

LIMIT 似乎不喜欢计算。尝试使用变量并在存储过程中使用该值

DECLARE v_page_offset INT DEFAULT 0;
SET v_page_offset = 10*(page-1);

后来

LIMIT 10 OFFSET v_page_offset;

【讨论】:

    猜你喜欢
    • 2014-08-31
    • 2019-04-30
    • 1970-01-01
    • 2022-06-14
    • 1970-01-01
    • 2018-03-07
    • 1970-01-01
    • 1970-01-01
    • 2021-05-26
    相关资源
    最近更新 更多