使用 MySQL,如何使用 phpmyadmin 将用户定义的数据库函数从一个数据库服务器导入另一台数据库服务器?
可以使用以下 SQL 获取用户定义函数的列表:
select * from information_schema.routines;
这是我想移动到不同数据库服务器的函数:
CREATE DEFINER=`XXX`@`%` FUNCTION `BDayDiff`( d1 DATE, d2 DATE ) RETURNS int(11)
DETERMINISTIC
BEGIN
DECLARE dow1, dow2, days, wknddays INT;
SET dow1 = DAYOFWEEK(d1);
SET dow2 = DAYOFWEEK(d2);
SET days = DATEDIFF(d2,d1);
SET wknddays = 2 * FLOOR( days / 7 ) +
IF( dow1 = 1 AND dow2 > 1, 1,
IF( dow1 = 7 AND dow2 = 1, 1,
IF( dow1 > 1 AND dow1 > dow2, 2,
IF( dow1 < 7 AND dow2 = 7, 1, 0 )
)
)
);
RETURN FLOOR(days - wkndDays);
END
但我收到一个错误:
Error
SQL query:
CREATE DEFINER = `XXX`@`%` FUNCTION `BDayDiff` (
d1 DATE,
d2 DATE
) RETURNS INT( 11 ) DETERMINISTIC BEGIN DECLARE dow1,
dow2,
days,
wknddays INT;
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 '' at line 5