2016-05-24 53 views
1

我新的MySQL和我试图从旧站点导入一个数据库到一个新的服务器,但我不断收到以下错误:#1305 - 功能XXXX不存在

#1305 - FUNCTION data_mysql.sp_get_user_balance does not exist

这里我正在使用的SQL:

DELIMITER $$ 
-- 
-- Functions 
-- 
DROP FUNCTION IF EXISTS `sp_get_user_balance`$$ 
$$ 

DROP FUNCTION IF EXISTS `sp_get_user_balance_sys`$$ 
$$ 

DELIMITER ; 

CREATE VIEW `transactions_detail` AS 
    select `tx`.`id` AS `id` 
    , `tx`.`transaction_id` AS `transaction_id` 
    ,date_format(`tx`.`tdate`,'%Y/%m/%d') AS `tdate` 
    ,date_format(`tx`.`tdate`,'%T') AS `ttime` 
    ,`tx`.`tdate` AS `tdatetime` 
    ,`tx`.`sender_id` AS `sender_id` 
    ,if((`t`.`transaction_type` = 'Withdrawal'),`sp_get_user_balance`(`tx`.`sender_id`),0) AS `sender_balance` 
    ,`tx`.`receiver_id` AS `receiver_id` 
    ,`st`.`username` AS `sender_name` 
    ,`rt`.`username` AS `receiver_name` 
    ,`tx`.`invoice_number` AS `invoice_number` 
    ,`p`.`name` AS `product_name` 
    ,`p`.`price` AS `product_price` 
    ,cast(if(isnull(`tx`.`sender_id`),`tx`.`amount`,-(`tx`.`amount`)) as decimal(11,2)) AS `oamount` 
    ,cast(`tx`.`amount` as decimal(11,2)) AS `amount` 
    ,cast(if((`tx`.`receiver_id` is not null) 
    ,(`tx`.`amount` - `tx`.`fees`),0) as decimal(11,2)) AS `nets` 
    ,cast(`tx`.`fees` as decimal(11,2)) AS `fees` 
    ,`s`.`transaction_status` AS `status` 
    ,`t`.`transaction_type` AS `type` 
    ,ifnull(`tx`.`comments`,'--') AS `comments` 
    ,`tx`.`can_view` AS `can_view` 
    ,`tx`.`can_refund` AS `can_refund` 
    ,`tx`.`cc_email` AS `cc_email` 
    ,`tx`.`cc_name` AS `cc_name` 
from (((((`t_transactions` `tx` 
    join `s_transaction_type` `t` on((`tx`.`transaction_type_id` = `t`.`id`))) 
    join `s_transaction_status` `s` on((`tx`.`transaction_status_id` = `s`.`id`))) 
    left join `t_products` `p` on((`tx`.`product_id` = `p`.`id`))) 
    left join `t_members` `st` on((`tx`.`sender_id` = `st`.`id`))) 
    left join `t_members` `rt` on((`tx`.`receiver_id` = `rt`.`id`)) 
); 

任何帮助将不胜感激。

回答

1

CREATE VIEW语句使用您在上一行中删除的sp_get_user_balance函数。

您错过了重建它的CREATE FUNCTION声明。

您可以使用SHOW CREATE FUNCTION sp_get_user_balance从旧网站导出。

或者如果它在后面的导入文件中,您可以对语句进行重新排序,使其在transactions_detail视图定义之前出现。