試圖寫在mysql中這個功能,但它給錯誤:寫作MySQL的功能,但未能
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 'IF Per='hour' THEN SET t=Price ; END IF; IF Per='day' THEN SET t=Price/24; END ' at line 8
DELIMITER$$
CREATE FUNCTION PricePerHour (Price REAL, Per VARCHAR(5))
RETURNS REAL
DETERMINISTIC
BEGIN
DECLARE t REAL;
IF Price IS NOT NULL AND Per IS NOT NULL
IF Per='hour' THEN SET t=Price ; END IF;
IF Per='day' THEN SET t=Price/24; END IF;
IF Per='week' THEN SET t=Price/7/24; END IF;
IF Per='month' THEN SET t=Price/30/24; END IF;
IF Per='year' THEN SET t=Price/365/30/24; END IF;
RETURN t;
END IF;
END $$
DELIMITER;
任何幫助,應該理解。提前Thanx。
刪除了sql server的標籤,因爲這個帖子與ms sql無關 – 2012-08-03 14:24:24