I am trying to insert data to MySQL using a stored procedure. The text values are getting inserted but the datetime has an issue. Here is the part of the code.
CALL `usp_UpdateStudent`("
<ArrayOfStudent>
<Student>
<ReadTime>2017-03-31T13:14:27Z</ReadTime>
</Student>
<Student>
<ReadTime>2017-03-31T13:14:27Z</ReadTime>
</Student>
</ArrayOfStudent>");
Stored Procedure
CREATE DEFINER=`root`@`localhost` PROCEDURE `usp_UpdateStudent`(tblStudent longtext)
BEGIN
DECLARE k INT UNSIGNED DEFAULT 0;
DECLARE row_count INT UNSIGNED;
DECLARE xpath TEXT;
DROP TEMPORARY TABLE IF EXISTS `StudentTemp`;
CREATE TEMPORARY TABLE StudentTemp (ReadTime datetime);
SET row_count := extractValue(tblTag,'count(/ArrayOfStudent/Student)');
WHILE k < row_count DO
SET k := k + 1;
SET xpath := concat('/Student[', k, ']');
INSERT INTO StudentTemp VALUES (
DATE_FORMAT(extractValue(tblTag, concat(xpath,'/ReadTime')),'%Y-%m-%d %H:%i:%s')
);
END WHILE;
insert into student select * from StudentTemp;
END
Table
CREATE TABLE `student` (
`ReadTime` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Error
Error Code: 1292. Incorrect datetime value: ''