MySQL Trigger - Storing a SELECT in a variable

后端 未结 6 1297
孤独总比滥情好
孤独总比滥情好 2020-12-02 22:16

I have a trigger in which I want to have a variable that holds an INT I get from a SELECT, so I can use it in two IF statements instead of calling the SEL

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 22:32

    As far I think I understood your question I believe that u can simply declare your variable inside "DECLARE" and then after the "begin" u can use 'select into " you variable" ' statement. the code would look like this:

    DECLARE
    YourVar  varchar(50);
    begin 
    select ID into YourVar  from table
    where ...
    

提交回复
热议问题