【问题标题】:I want to create store Procedure dynamically comma separated columns and values我想动态创建存储过程,以逗号分隔的列和值
【发布时间】:2018-11-30 07:30:43
【问题描述】:

我将值传递给存储过程。逻辑是用逗号分割值并使用循环。

@Colomns Id,Firstname,Lastname
@values 1,'foo','bar'

查询应该是

Select * from user where Id = 1 and Firstname = 'foo' and Lastname = 'bar'

【问题讨论】:

标签: mysql sql database stored-procedures


【解决方案1】:

只需使用substring_index()concat()

Select *
from user
where concat_ws(Id, firstname, lastname) = @param;

然后,将存储过程修复为采用三个参数!将三个值放入一个字符串中没有任何优势,而不是传入三个单独的值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多