使用delimiter //,解決mysql end報錯問題


這是我的初始報錯的代碼:

1 create procedure search_sc (student_no varchar(6))
2     begin
3         select sc.* 
4         from sc
5         where sno= student_no
6     end;

會報這個錯誤,“Error Code: 1064. 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 'end' at line 6問題”

解決后:

delimiter //
create procedure search_sc (student_no varchar(6))    
    begin
        select sc.* 
        from sc
        where sno= student_no;
    end //

原來是因為mysql解釋器根據‘;’來結束讀取命令執行命令,在多個‘;’號時,解釋器不知到在哪一句結束讀取命令執行命令,而delimiter的作用是,將sql結束讀取命令並執行命令的標志,替換成delimiter后的標志(在本文是‘//’),這樣只有當‘//’出現之后,mysql解釋器才會執行這段語句。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM