【问题标题】:convert comma separated string values into integer values in mysql在mysql中将逗号分隔的字符串值转换为整数值
【发布时间】:2021-03-04 03:06:16
【问题描述】:

我有一个逗号分隔的字符串变量 v_combined_prodid 。 但是我想将逗号分隔的字符串变量转换为逗号分隔的 int 值或在循环中我们可以使用 where 子句 prodid 作为 int 更新一个表。 我们不能使用 FIND_IN_SET(prodid, v_combined_prodid )

我们可以使用存储过程。

DECLARE v_combined_prodid varchar(800);

set v_combined_prodid ='1,2,3,4,5';

below statement exactly requirement.

update mytable t set t.status=2
 WHERE prodid in (1,2,3,4,5)
 and t.status=0 ;

【问题讨论】:

  • P Nayak,下面的答案对您有帮助吗?如果是这样,您可以选择将答案标记为已接受。这是你的选择。用接受的答案标记您的问题将结束您的问题。

标签: mysql


【解决方案1】:

你最好创建一个动态查询然后执行它。

有关示例,请参阅 Mysql dynamically build query string in a stored procedure based on logic

DECLARE v_combined_prodid varchar(800);

set v_combined_prodid ='1,2,3,4,5';

set @query = CONCAT(' update mytable t set t.status = 2 where prodid in ('
                    , v_combined_prodid
                    , ') and t.status = 0');

PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

【讨论】:

    猜你喜欢
    • 2016-02-08
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-12
    相关资源
    最近更新 更多