CASE语句,在THEN部分分配多个值
之前已经有人问过这个问题,但我不确定是否得到了明确的回答。如何在 CASE 语句的 THEN 部分中分配多个值。根据MySQL手册“每个statement_list由一个或多个语句组成;”,所以我想知道这是如何完成的。
我的 CASE 语句中有一个 THEN,并且想为两个变量赋值。所以类似 THEN @var1 := 'something', @var2 := 'something else' ESLE 'something more' END。
这可能吗?
This has been asked before but I'm not sure it was clearly answered. How do you assign multiple values in the THEN portion of a CASE statement. According to the MySQL manual "Each statement_list consists of one or more statements;", so I'm wondering how this is done.
I have a THEN in my CASE statement and would like to assign a value to two variables. So something like THEN @var1 := 'something', @var2 := 'something else' ESLE 'something more' END.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为你能够在案例本身内部分配变量,除非 MySql 与 TSQL 不同,但这里是你如何完成你想要做的事情:
希望有帮助
I don't think you'll be able to assign variables inside of the case itself, unless MySql is that different from TSQL, but here is how you can accomplish what you are trying to do:
hope that helps
从您从文档中发布的链接中提取一些内容:
将多个语句封装在
BEGIN...END
.. 看看这是否有效Pulling a bit from the link you posted from the docs:
Encapsulate multiple statements within a
BEGIN...END
.. See if this works