Mysql custom function returns 0 how to do?

I use the mysql custom function, which always returns 0. I don"t know how to do it. `CREATE FUNCTION CountLayer (typeid int) RETURNS int (12)
BEGIN

-sharpRoutine body goes here...
declare result int;
    declare lft int;
    declare rgt int;
declare c int;
     
    set c = 0;
    set result = 0;
set lft = 0;
    set rgt = 0;
                     
    select count(*) into result from tree where Lft <= 2 and Rgt >= 11;
RETURN result;

END`

The

table structure data is like this.

DROP TABLE IF EXISTS tree ;
CREATE TABLE tree (
Type_id int (12) UNSIGNED NOT NULL AUTO_INCREMENT,
Name varchar (20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
Lft int (12) NOT NULL,
Rgt

--
-- Records of tree
-
INSERT INTO tree VALUES (1, "commodity", 1, 18);
INSERT INTO tree VALUES (2, "food", 2, 11);
INSERT INTO tree VALUES (3, "meat", 3,6);
INSERT INTO tree VALUES (4, "pork", 4,5);
INSERT INTO tree VALUES (5, "vegetables", 7,10);
INSERT INTO tree VALUES (6, "cabbage", 8,9);
INSERT INTO tree VALUES (7, "Electrical", 12,17);
INSERT INTO tree VALUES (8,"TV")

always returns 0, but the actual select count (*) from tree where Lft < = 2 and Rgt > = 11; the query result is 2.
if I set result = 100, then return is OK. That"s weird.
what does Baidu say? to turn on the custom function switch, mine is on.

what"s going on?

Mar.31,2021

is too lame. I checked it over and over 200 times and found that lft,rgt, seems to be a system variable. I don't think so. Left,right is. Just change it to another field name. It's bad luck for anyone to meet. I am version 5. 7 mysql.


select result: = count (*) from tree where.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b268d7-2b815.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b268d7-2b815.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?