Why delimiter used with stored procedure in mysql?

后端 未结 1 1147
刺人心
刺人心 2021-01-26 11:00

I am trying to understand, why delimiter used with stored procedure in mysql? but i couldn\'t.

DELIMITER //
CREATE PROCEDURE GetAllProducts()
   BEGIN
       SEL         


        
1条回答
  •  一整个雨季
    2021-01-26 11:08

    Mysql's default delimiter is ; which is used for one statement in the command line , something as

    select * from users ;
    

    When you write a trigger or stored procedure to execute the entire code mysql needs to understand that its a block of code/query.

    If no delimiter is provided then when mysql encounters any ; inside the store procedure or trigger it will think that as one statement and will try to execute it. So we need to provide a delimiter for store procedure or trigger and make mysql understand that anything within that delimiter is one complete set of code.

    So in your example

    SELECT * FROM products; 
    

    it will be a part of the complete statement when there is a delimiter other than ; is provided at the beginning.

    0 讨论(0)
提交回复
热议问题