What's wrong with this MySQL statement: DECLAR

2019-02-22 11:28发布

问题:

DECLARE @ID INT ;

This statement parses fine with MS SQL Server, but gives me

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE @ID INT' at line 1

Does anyone have any idea about the reason?

回答1:

DECLARE is used in stored procedures/functions.

If you're looking to set a variable for just regular queries, use SET



回答2:

try naming the variable without the @

DECLARE id INT;


回答3:

We can't use Declare in normal queries.

Try this:

SET @ID =(Select id from mytable)


标签: sql tsql mysql