我有一张名为staff
的表格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不能为空'")
但是当我在简单的插入语句中传递相同的值时
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');
它被插入。
那么,我的存储过程出了什么问题......如何通过存储过程传递值? 请帮忙
答案 0 :(得分:3)
在过程中使用不带@
符号的参数。我的意思是你在程序中的插入语句应该像
INSERT INTO staff
(`fname`,
`lname`,
`address`,
)
VALUES
(fnme,
lnme,
address,
);