mysql环境中,如何用sql语句给字符串变量赋值?

mysql环境中,如何用sql语句给字符串变量赋值?,第1张

mysql给字符串变量赋值的方法是用select into 变量结构完成赋值。使用sql的结构语法:SELECT ... INTO var_list selects column values and stores them into variables.比如定义一个sql变量:@x varchar(10)@y varchar(20)select id,name INTO @x,@y from dx_tt 这样就完成了赋值。

测试一下, 好像是可行的呀!

mysql> select @test := 1

+------------+

| @test := 1 |

+------------+

|          1 |

+------------+

1 row in set (0.00 sec)

mysql> select * from test_main

+----+-------+

| id | value |

+----+-------+

|  1 | ONE   |

|  2 | TWO   |

|  3 | THREE |

+----+-------+

3 rows in set (0.00 sec)

mysql> select * from test_main where id > @test

+----+-------+

| id | value |

+----+-------+

|  2 | TWO   |

|  3 | THREE |

+----+-------+

2 rows in set (0.00 sec)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7403515.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-05
下一篇 2023-04-05

发表评论

登录后才能评论

评论列表(0条)

保存