MySQL Forums
Forum List  »  Newbie

Why is it saying ' DECLARE' (declare) is not valid input at this position?
Posted by: Mark Kamoski
Date: June 20, 2016 07:31AM

Dear MySql Workbench Pros --

Please help a newbie to MySql Workbench.


Why is it saying ' DECLARE' (declare) is not valid input at this position?


-- This does work...


SELECT * FROM alerts WHERE update_number = 0;


-- This does NOT work...


-- Syntax error: 'DECLARE' (declare) is not valid input at this position

DECLARE @update_number INT;


SET @update_number = 0;


SELECT * FROM alerts WHERE update_number = @update_number;


...so WHY is that syntax not correct?


I noticed that I can just skip the DECLARE line altogether, but then my question is how is the variable datatype set when the DECLARE line is omitted? Is the datatype set dynamically based on the value assigned with the SET there? Or what?

So, is there a way to use the DECLARE statement in such a case?

Please advise.

(This is specifically about the DECLARE syntax. I have read about user-defined-variables and local-variables and system-variables. So I am wondering about the use of the DECLARE keyword in the example above and how the data-type is set when the DECLARE keyword is not used, etc.)

Thanks.

-- Mark Kamoski

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.