错误代码:mysql中的1064

时间:2011-10-28 06:58:41

标签: mysql mysql-error-1064

我创建了一个应该执行某些操作的过程,但每次调用它时,mysql都会出现错误,我不知道这意味着什么。我试图理解它是徒劳的,这是存储过程在其上进行操作的表结构:

CREATE  TABLE `recruitment`.`job_seeker` (
    `user_id` INT Null ,
    `fname` VARCHAR(45) Null ,
    `lname` VARCHAR(45) Null ,
    `mname` VARCHAR(45) Null ,
    `gender` VARCHAR(10) Null ,
    `dob` DATE Null ,
    `marital_status` VARCHAR(45) Null ,
    `address` VARCHAR(45) Null ,
    `city` VARCHAR(45) Null ,
    `nationality` VARCHAR(45) Null ,
    `phone` VARCHAR(45) Null ,
    `mobile` VARCHAR(45) Null ,
    `degree_id` INT Null ,
    `education` VARCHAR(100) Null ,
    `experience` VARCHAR(250) Null ,
    `other` VARCHAR(250) Null ,
    `job_target` VARCHAR(250) Null ,
    PRIMARY KEY (`user_id`) ,
    INDEX `user_id` (`user_id` ASC) ,
    INDEX `degree_id` (`degree_id` ASC) ,
    CONSTRAINT `user_id`
    FOREIGN KEY (`user_id` )
    REFERENCES `recruitment`.`user_authentication` (`user_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
    CONSTRAINT `degree_id`
    FOREIGN KEY (`degree_id` )
    REFERENCES `recruitment`.`degree` (`degree_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION
);

这是存储过程:

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `createSeekerProfile`(in userName varchar(45),
    in fn varchar(45),in mn varchar(45), in ln varchar(45),
    in gender varchar(6),in nationality varchar(45),
    in ad varchar(45),in city varchar(45),in phone varchar(15),in mob varchar(15),

    in   maritalStatus varchar(45), in degId int, in educ varchar(100),
    in exper varchar(250), in other   varchar(250),
    in dob date,in jtarg varchar(250))
    begin
    declare returned_ID int;
    set @dyn_que = CONCAT('select user_id into @returned_ID
    from user_authentication where user_name =  ? ');
    prepare s1 from @dyn_que ;
set @usn = userName;
execute s1 using @usn ;

set @dyn_update =CONCAT('update job_seeker set fname =',fn,', lname = ',ln,' ,mname = ',mn,' ,
nationality =',nationality,',address =',ad,',city =',city,',phone=',phone,',
mobile =',mob,', gender = ',gender,',other =',other,',
degree_id =',degId,', job_target=',jtarg,', dob =',dob,', education =',educ,',
experience=',exper,', marital_status=',maritalStatus,' where user_id =@returned_ID');
prepare s2 from @dyn_update;
execute s2;
end

每当我通过以下方式致电程序时:

call createSeekerProfile('realsilhouette','robert','marie','david','male'
,'earthal','an address here','capital of earth','012178152',
'1111111111','single',2,'engineering','looking forward','determined',
'2008-7-04','Oracle CEO')

我收到一个可怕的错误:

Error Code: 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 'address here,
city =capital of earth,phone=012178152,
mobile =1111111111, gender' at line 2

但是当我尝试在存储过程中手动执行update语句时,它运行得很好。

新帖子:  感谢上帝,最后我解决了问题,问题归结为顺序,我所做的只是按顺序制作参数,虽然更新语句不关心顺序,据我所知,我不确定,但我确信存储过程是精美创建的,这是新代码:

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `createSeekerProfile`(
in un varchar(45),
in fn varchar(45),
in ln varchar(45), 
in mn varchar(45),
in g varchar(10),
in dateOfBirth date,
in ms varchar(45),
in ad varchar(45),
in city varchar(45),
in nat varchar(45),
in ph varchar(45),
in mob varchar(45),
in degid int,
in educ varchar(100),
in exp varchar(250),
in other varchar(250),
in jtarg varchar(250))
begin

declare returned_ID int(11);

 set @dyn_que = CONCAT('select user_id into @returned_ID from user_authentication
 where user_name =  ? ');
 prepare s1 from @dyn_que ;
 set @usn = un;
 execute s1 using @usn ;


 set @dyn_update =CONCAT('update job_seeker set fname  
 ="',fn,'",lname="',ln,'",mname="',mn,'",lname ="',ln,'",
 gender ="',g,'",dob="',dateOfBirth,'",marital_status="',ms,'",
 address="',ad,'",city="',city,'",
 nationality="',nat,'",phone="',ph,'",mobile="',mob,'",degree_id="',
 degid,'",education="',educ,'",
 experience="',exp,'",other="',other,'",job_target="',jtarg,'" 
 where user_id = @returned_ID');
 prepare stm from @dyn_update;
 execute stm;
 end $$
非常感谢

3 个答案:

答案 0 :(得分:4)

您忘了引用字符串值。

例如:

concat('update yourTable
set address ="',  @address, '" 
where id = 1');

或使用函数quote

答案 1 :(得分:2)

对我来说,添加字符`(GRAVE ACCENT)有帮助。它不是单引号(')

答案 2 :(得分:2)

CREATE TABLE Order
( 
    Order_Id             integer  NOT NULL ,
    Order_Time           datetime  NULL ,
    Order_Status         char(50)  NULL ,
    Customer_Id          integer  NOT NULL 
)