我有一张叫员工的桌子

CREATE TABLE `staff` (
`idstaff` int(11) NOT NULL AUTO_INCREMENT,
`fname` varchar(45) NOT NULL,
`lname` varchar(45) NOT NULL,
`address` varchar(45) NOT NULL,
`gender` varchar(45) NOT NULL,
`bloodgroup` varchar(3) NOT NULL,
`dob` date NOT NULL,
`mobile_no` varchar(45) NOT NULL,
`email` varchar(45) NOT NULL,
`qualification` varchar(45) NOT NULL,
`department` varchar(45) NOT NULL,
`designation` varchar(45) NOT NULL,
`joindate` date NOT NULL,
`retiredate` date NOT NULL,
`refname` varchar(45) NOT NULL,
`mobile` varchar(45) NOT NULL,
`relationship` varchar(45) NOT NULL,
PRIMARY KEY (`idstaff`)
) ENGINE=InnoDB AUTO_INCREMENT=1003 DEFAULT CHARSET=utf8;


这是我用于插入数据的存储过程

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_staffs`(
IN fnme varchar(45),
IN lnme varchar(45),
IN address varchar(45),
IN gender varchar(45),
IN bloodgroup varchar(3),
IN dateob date,
IN mobilenum varchar(45),
IN email varchar(45),
IN edu varchar(45),
IN department varchar(45),
IN designation varchar(45),
IN joindate date,
IN retiredate date,
IN refname varchar(45),
IN refnum varchar(45),
IN rel varchar(45))
BEGIN
INSERT INTO staff
(`fname`,
`lname`,
`address`,
`gender`,
`bloodgroup`,
`dob`,
`mobile_no`,
`email`,
`qualification`,
`department`,
`designation`,
`joindate`,
`retiredate`,
`refname`,
`mobile`,
`relationship`)
VALUES
(@fnme,
@lnme,
@address,
@gender,
@bloodgroup,
@dateob,
@mobilenum,
@email,
@edu,
@department,
@designation,
@joindate,
@retiredate,
@refname,
@refnum,
@rel
);
END$$
DELIMITER ;


当我打电话给程序时

call insert_staffs('gore','asdf','asdf','m','ab','1980/03/29','safd','asdf','asdf',
'asdf','asdf','2000/01/04','2030/01/03','sdaf','sdaf','sadf');


它将引发1048错误(“列'fname不能为null'”)

但是当我在简单的插入语句中传递相同的值时

INSERT INTO `hospitalmgmt`.`staff`
(`fname`,
`lname`,
`address`,
`gender`,
`bloodgroup`,
`dob`,
`mobile_no`,
`email`,
`qualification`,
`department`,
`designation`,
`joindate`,
`retiredate`,
`refname`,
`mobile`,
`relationship`)
VALUES
(
'gore','asdf','asdf','m','ab','1980/03/29','safd','asdf',
'asdf','asdf','asdf','2000/01/04','2030/01/03','sdaf','sdaf','sadf');


它被插入。

那么,我的存储过程出了什么问题...我该如何通过存储过程传递值?
请帮忙

最佳答案

在过程中使用不带@符号的参数。我的意思是你的过程中的插入语句应该像

INSERT INTO staff
(`fname`,
`lname`,
`address`,
)
    VALUES
    (fnme,
    lnme,
    address,
    );

关于mysql - 1048错误,即使将值赋给mysql列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23729530/

10-10 03:52