我导入了一个 MySQL 数据库。成功导入的所有表,但不是函数。我可以执行 SQL 查询的唯一方法是通过 phpMyAdmin 或使用 PHP 脚本(无 SSH)。
这是要导入的函数的示例:
DELIMITER ;;
/*!50003 DROP FUNCTION IF EXISTS `f_calc_gst` */;;
/*!50003 SET SESSION SQL_MODE=""*/;;
/*!50003 CREATE*/ /*!50020 DEFINER=`journal`@`%`*/ /*!50003 FUNCTION `f_calc_gst`(p_ht decimal(15,3), p_province varchar(2)) RETURNS varchar(255) CHARSET utf8
begin
declare res varchar(255);
declare v_gst decimal(15,3);
declare v_gst_formula varchar(255);
select GST, GST_formula
into v_gst, v_gst_formula
from taxes_periods
where NOW() between dt_debut and dt_fin
and id_province = p_province;
set v_gst_formula = replace(v_gst_formula, 'HT$', p_ht);
set v_gst_formula = replace(v_gst_formula, 'GST%', v_gst);
set res = concat('select round(', v_gst_formula, ',2) "gst"');
return res;
end */;;
如果我将此代码粘贴到 phpMyAdmin 中,我会收到此错误:#1227 - Access denied; 您需要此操作的 SUPER 权限
我尝试删除“/ !50003”和“ /”以取消注释 SQL,但我收到相同的错误消息。
我还尝试不使用任何分隔符并删除“DELIMITER ;;” 并得到这个错误:
DROP FUNCTION IF EXISTS f_calc_gst SET SESSION SQL_MODE = "" CREATE DEFINER = `journal`@`%` FUNCTION `f_calc_gst` (
p_ht DECIMAL( 15, 3 ) ,
p_province VARCHAR( 2 )
) RETURNS VARCHAR( 255 ) CHARSET utf8 BEGIN declare res VARCHAR( 255 ) ;
#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 'SET SESSION SQL_MODE=""
CREATE DEFINER=`journal`@`%` FUNCTION `f_calc_gst`(p_ht ' at line 2
也试过:
CREATE DEFINER=`journal`@`%` FUNCTION `f_calc_gst`(p_ht decimal(15,3), p_province varchar(2)) RETURNS varchar(255) CHARSET utf8
begin
declare res varchar(255);
declare v_gst decimal(15,3);
declare v_gst_formula varchar(255);
select GST, GST_formula
into v_gst, v_gst_formula
from taxes_periods
where NOW() between dt_debut and dt_fin
and id_province = p_province;
set v_gst_formula = replace(v_gst_formula, 'HT$', p_ht);
set v_gst_formula = replace(v_gst_formula, 'GST%', v_gst);
set res = concat('select round(', v_gst_formula, ',2) "gst"');
return res;
end//
导致 :
#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 3
问题出在 SQL、phpMyAdmin 还是服务器?