mysql程序:语法,语法,语法......太难找了

时间:2016-06-08 13:26:21

标签: mysql stored-procedures

这是我的程序:

delimiter //
drop procedure if exists migContactToActor;
create procedure migContactToActor()
begin
        declare vctaid int;
        declare firstname char(255);
        declare lastname char(255);
        declare phone char(255);
        declare cellphone char(255);
        declare fax char(255);
        declare mail char(255);
        declare location char(255);
        declare extcode char(255);
        declare vcpyid int;
        declare vquaid int;
        declare userModif char(255);
        declare entityIdResp int;
        declare niveauCreat char(255) default "contactMigration2.21";
        declare userCreat char(255) default "contactMigration2.21";
        declare backIdResp int;
        declare userIdResp int;
        declare zipcode char(255);
        declare country char(255);
        declare dateModif char(255);
        declare dateCreated char(255);
        declare dateRelation char(255);
        declare groupLabel char(255);
        declare adminLogId int;
        declare finContact boolean default 0;
        declare ctt int default 1; /* decompte contacts */
        declare entityName char(255) default ''; /* entite courante du user a linker */
        declare entityId int default 0; /* et son Id */
        declare vctaidPrev int default 0;

        declare curs1 cursor for select
                ctaid, ctafirstname,ctalastname,ctaphone,ctacellphone,ctaemail,
                substr(concat_ws(' ',ctaaddress,ctaaddress2,ctacity,ctazipcode),1,255),ctacode, cpyid,quaid,C.enoid_resp,
                ctafax,C.actid_bck,ctadate_created,ctacountry,ctadate_modified,C.actid_resp,ctauser_modified, G.hemlabel, R.sync_update
                from contact C
                left join hd_contact_group_relationship R on R.hbhid = C.ctaid
                left join hd_contact_group G on G.hemid = R.hemid
                where !ifnull(C.ctaflagdeleted,0) and !ifnull(G.hemflag_deleted,0);
        declare continue handler for not found set finContact = 1;
        declare continue handler for sqlexception
        begin
                rollback;
        end;

        select '======== debut ...';
        drop table if exists ent221;
        create temporary table ent221 as select enoid, enoname from entityowner where enoname like 'CLI.CG_%.CLI';
        alter table ent221 add index(enoname); /* not unique in dev, fetch the first in prod if any */

        set autocommit = 0; /* TTT */
        start transaction; /* TTT */
        open curs1;
        contactloop:loop
                fetch curs1 into vctaid, firstname,lastname,phone,cellphone,mail,location,extcode,vcpyid,vquaid,entityIdResp,
                        fax,backIdResp,dateCreated,country,dateModif,userIdResp,userModif,groupLabel,dateRelation;
                if finContact then
                        close curs1;
                        leave contactloop;
                end if;
                if vctaid = vctaidPrev then
                        set vctaidPrev = vctaid;
                        if (mod(ctt,100) = 0) then
                                set @msg = concat(ctt, ' contacts migrated');
                                select @msg;
                        end if;
                        update OPMSequence set counter = (@wbuf1 := counter) + 1 where name = 'ACTOR';
                        insert into actor (actid,cpyid,actlastname,actfirstname,actemail,actphone,actmobilephone,
                                        actlocalisation, actid_responsible_owner,actid_backup_owner,enoid_responsible_owner,
                                        actuser_created,actniveau_created, actdate_created,actuser_modified,
                                        actdate_modified,actcountry,actfax,actqualifid,actexternal_code)
                                values
                                        (@wbuf1,vcpyid,lastname,firstname,mail,phone,cellphone,location,userIdResp,backIdResp,entityIdResp,
                                                userCreat,niveauCreat,dateCreated,userModif,dateModif,country,fax,vquaid,extcode);

                        update adminLog set adltype = 'User', adlobject_id = @wbuf1,
                                adlobject_description = concat(adlobject_description,'//oldContact=',vctaid)
                                where adlobject_id = vctaid and adltype = 'Contact';
                end if;

                if groupLabel is not null then
                        set @entName = concat('CLI.CG_',groupLabel,'.CLI);
                        select enoid from ent221 where enoname = @entName limit 1 into @wbuf2;
                        if @wbuf2 is not null then
                                insert into actorentityrelationship (enoid,actid,aerdate_created,aerniveau_created) values
                                        (@buf2,@wbuf1,dateRelation,niveauCreat);
                        enf if;
                end if;
                set ctt = ctt + 1;
        end loop contactloop;
        rollback; /* TTT */
end //

delimiter ;
call migContactToActor;
drop procedure migContactToActor;

为什么这个? 查询正常,0行受影响,1警告(0.00秒)

  

错误1064(42000):您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以便在#"' .CLI)附近使用正确的语法;                           从ent221中选择enoid,其中enoname = @entName limit 1进入@ wbuf2'在第83行

1 个答案:

答案 0 :(得分:0)

我认为你错过了报价

set @entName = concat('CLI.CG_',groupLabel,'.CLI);

带引号

set @entName = concat('CLI.CG_',groupLabel,'.CLI');