簡體   English   中英

在 MySQL Workbench 中創建 function 時出錯

[英]Error when creating function in MySQL Workbench

我正在嘗試在 MySQL 工作台中定義一個 function。 有一個錯誤顯示“@node_id 在此 position 中無效,需要一個標識符”,並且在變量名 @node_id 下顯示了一條紅線。 誰能幫我檢查一下我的代碼問題出在哪里? 非常感謝!

CREATE FUNCTION dbo.CountLayer  
(  
    @node_id int  
)  
RETURNS int  
AS  
begin  
    declare @result int  
    set @result = 0  
    declare @lft int  
    declare @rgt int  
    if exists(select Node_id from Tree where Node_id = @node_id)  
    begin  
        select @lft = Lft, @rgt = Rgt from Tree where node_id = @node_id  
        select @result = count(*) from Tree where Lft <= @lft and Rgt >= @rgt  
    end  
    return @result  
end  
GO;

正如評論所說,這不是 MySql。 你不使用@ ,你必須有; 在此處查看此鏈接以獲取 if-else 語句

還為您的 function 檢查此結構

DELIMITER $$
CREATE FUNCTION pl2.test2
(  
    node_id int  
)  
RETURNS int
begin  
    declare result int ; 
     declare  lft int ; 
    declare rgt int;  
    set result = 0 ; 
   your if statment
   
    return result ;

END $$
DELIMITER ;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM