0

你能告诉我我的mysql函数有什么问题吗?

DELIMITER //
CREATE FUNCTION avgRating( ide int(11), ident bool ) RETURNS float
BEGIN
IF ident!=1 THEN

RETURN (
SELECT SUM(RatingVal)/Count(*) 
FROM ratings WHERE id=ide
GROUP BY id
);
ELSE RETURN (
SELECT SUM(RatingVal)/Count(*) 
FROM ratings WHERE id=ide
GROUP BY id);
END IF;
END //
DELIMITER ;

导入文件后来自 phpMyAdmin 的错误:

        Error
There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem

ERROR: Unknown Punctuation String @ 104
STR: //
SQL: DROP FUNCTION IF EXISTS `avgRating`;# MySQL returned an empty result set (i.e. zero rows).

DELIMITER //
CREATE FUNCTION `avgRating`( ide int(11), ident bool ) RETURNS float
BEGIN
    IF ident!=1 THEN

    RETURN (
    SELECT SUM(RatingVal)/Count(*) 
    FROM ratings WHERE id=ide
    GROUP BY id
    );
    ELSE RETURN (
    SELECT SUM(RatingVal)/Count(*) 
    FROM ratings WHERE id=ide
    GROUP BY id);
    END IF;
END //

DELIMITER //
CREATE FUNCTION `avgRating`( ide int(11), ident bool ) RETURNS float
BEGIN
    IF ident!=1 THEN

    RETURN (
    SELECT SUM(RatingVal)/Count(*) 
    FROM ratings WHERE id=ide
    GROUP BY id
    );
    ELSE RETURN (
    SELECT SUM(RatingVal)/Count(*) 
    FROM ratings WHERE id=ide
    GROUP BY id);
    END IF;
END //


SQL query: 

DELIMITER // CREATE FUNCTION `avgRating`( ide int(11), ident bool ) RETURNS float BEGIN IF ident!=1 THEN RETURN ( SELECT SUM(RatingVal)/Count(*) FROM ratings WHERE id=ide GROUP BY id ); ELSE RETURN ( SELECT SUM(RatingVal)/Count(*) FROM ratings WHERE id=ide GROUP BY id); END IF; END //

MySQL said: 

#1418 - This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable) 
4

0 回答 0