我習慣於在MS SQL Server中工作,所以MySQL對我來說總是有些陌生。我寫了MS SQL Server中的以下內容,我想將它移植到MySQL:在MySQL中創建函數時遇到問題
CREATE FUNCTION ToRadians
(@Degrees float)
RETURNS float
AS
BEGIN
DECLARE @Radians float
SELECT @Radians = @Degrees * 3.1415927/180
RETURN @Radians
END
GO
我有
CREATE FUNCTION ToRadians
(@Degrees float)
RETURNS float
BEGIN
DECLARE @Radians float;
SELECT @Radians = @Degrees * 3.1415927/180;
RETURN @Radians;
END
但在phpMyAdmin,這給我的錯誤:
Error
SQL query:
CREATE FUNCTION ToRadians(
@Degrees float
) RETURNS float AS BEGIN [email protected] float;
MySQL said: Documentation
#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 '@Degrees float)
RETURNS float
AS
BEGIN
DECLARE @Radians float' at line 2
我所做的搜索表明上面的MySQL UDF 應該是是正確的,但它顯然不是。 SELECT version()返回5.0.77
此外,事實證明,我不能使用SELECT在函數內進行數學運算。我應該使用SET Radians = Degrees * 3.1415927/180; – Chris
你也可以做'SELECT ... INTO [variable]'... – a1ex07