glzmzd 2015-09-16 08:58 采纳率: 20%
浏览 1605
已采纳

mysql导入.sql文件的问题

将一个.sql文件编辑,文本中最后加入下面这段代码(部分代码)后,导入这个sql文件就会报错(这段新加代码未能导入)
原因是什么?还有就是应该如何解决这个问题。多谢了!

 #
# Function "fun_getChildList"
#

DROP FUNCTION IF EXISTS `fun_getChildList`;
CREATE FUNCTION `fun_getChildList`(`type` int,`areaid` int,`orgid` int) RETURNS varchar(1000) CHARSET utf8
BEGIN


    DECLARE sTemp VARCHAR(1000);
    DECLARE xh VARCHAR(50);
    DECLARE areacode VARCHAR(100);
    DECLARE cunt INT;

    SELECT CONCAT(ORGXH,'%') INTO xh from ss_organization where ID_ORG=orgid;
    IF type=1 THEN
        set sTemp='$';
        SELECT CONCAT(sTemp,',',GROUP_CONCAT(ID_ORG)) INTO sTemp from ss_organization where ORGXH like xh;
    ELSEIF type=0 THEN
        SELECT COUNT(1) into cunt FROM ss_organization where ss_organization.ID_ORG=orgid and ss_organization.ORG_DISTRPARENTID=areaid;
        if cunt>0 then
        select area_code INTO areacode from bs_distrarea_info where area_id=areaid;
        SELECT IFNULL(GROUP_CONCAT(ID_ORG),'0') into sTemp from ss_organization 
        LEFT JOIN  bs_distrarea_info ON ORG_DISTRPARENTID=area_id where area_code like CONCAT(areacode,'%') and area_id<>areaid;
        SELECT CONCAT(sTemp,',',IFNULL(GROUP_CONCAT(ID_ORG),'0')) INTO sTemp from ss_organization where ORGXH like xh;
        ELSEIF cunt=0 THEN
        SELECT IFNULL(GROUP_CONCAT(ID_ORG),'0') into sTemp from ss_organization where ss_organization.ORG_DISTRPARENTID=areaid;
        end IF;
        SET sTemp=CONCAT('$',',',sTemp);
    END IF;
    RETURN sTemp;
END;

#
# Function "fun_getOrgLine"
#

DROP FUNCTION IF EXISTS `fun_getOrgLine`;
CREATE FUNCTION `fun_getOrgLine`(`orgid` int) RETURNS varchar(1000) CHARSET utf8
BEGIN

    DECLARE sTemp VARCHAR(1000);
    DECLARE sTempChd VARCHAR(1000);
    DECLARE grade INT;
    DECLARE enterprisename VARCHAR(100);
    DECLARE st INT;

    SELECT ss_organization.ORG_GRADE,ss_organization.ENTERPRISE_NAME into grade,enterprisename from ss_organization where ss_organization.ID_ORG=orgid;
    SET st=1;
     WHILE grade<=st DO
        set st=st+1;
     END WHILE;

    RETURN grade;
END;

#
# Function "getChildLst"
#

DROP FUNCTION IF EXISTS `getChildLst`;
CREATE FUNCTION `getChildLst`(rootId INT) RETURNS varchar(1000) CHARSET utf8
BEGIN
     DECLARE sTemp VARCHAR(1000);
       DECLARE sTempChd VARCHAR(1000);

       SET sTemp = '$';
       SET sTempChd =cast(rootId as CHAR);

       WHILE sTempChd is not null DO
         SET sTemp = concat(sTemp,',',sTempChd);
         SELECT group_concat(o.ID_ORG) INTO sTempChd FROM ss_organization o where FIND_IN_SET(o.ORG_PARENT_ID,sTempChd)>0;
       END WHILE;
    RETURN sTemp;
END;



  • 写回答

4条回答 默认 最新

  • QIUSQJF 2015-09-17 07:59
    关注

    如果你的函数本身没有语病,那么很可能是识别结尾符有问题,因为mysql默认;结尾,所以你直接这样写会导致执行失败,你在这些函数执行前加上
    DELIMITER $

    使用完后,也即在没有存储过程或者函数的时候再还原回来

    DELIMITER ;

    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥15 pyqt信号槽连接写法
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。