I would like to select one value in a variable. I have tried:
DECLARE myvar INT(4);
- immediately returns some syntax error.
SELECT myvalue FROM mytable WHERE anothervalue = 1;
- returns a single integer
SELECT myvalue INTO myvar FROM mytable WHERE anothervalue = 1;
- does not work, also tried @myvar
Can I use DECLARE outside stored procedures or functions?
Maybe I just don’t understand the concept of user variables ... I just tried:
SELECT myvalue INTO @var FROM `mytable` WHERE uid = 1; SELECT @var;
... who worked the way he should. But if I run each request at a time, I just get @var NULL.
mysql select declare mysql-workbench
Matt Bannert Jun 19 '10 at 10:21 2010-06-19 10:21
source share