我正在尝试创建一个过程检查表并插入 但它向我显示了一些错误,我不确定如何解决它
这是错误代码
存储函数或不允许显式或隐式提交 触发
DELIMITER ;;
CREATE FUNCTION `getLabel`(paradocid INT, paradoctype char(10),paradoclineid INT,paraqty INT,paracreated date,paracreatedby INT) RETURNS int(100)
BEGIN
DECLARE transtotal int;
DECLARE i int DEFAULT 0;
DECLARE total int;
CREATE TABLE IF NOT EXISTS `sim_lable`(
`label_id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
`doctype` varchar(10) NOT NULL,
`docid` int NOT NULL,
`doclineid` int NOT NULL,
`created` date NOT NULL,
`createdby` int NOT NULL
) ENGINE='InnoDB' COLLATE 'utf8_unicode_ci';
DELETE FROM sim_lable where
(TIME_TO_SEC(TIMEDIFF(paracreatedby,createdby))/60) >30;
SELECT @total=coalesce(count(*),0) as total2 from sim_label where
doctype=paradoctype and paradocid=docid;
IF total = 0 THEN
WHILE i < paraqty DO
INSERT INTO dbo.Students
(
`doctype` ,
`docid`,
`doclineid` ,
`created` ,
`createdby`
)
VALUES
(
paradoctype,
paradocid,
paradoclineid,
paracreated,
paracreatedby
) ;
END WHILE;
END IF;
END
答案 0 :(得分:0)
如错误消息所示,存储函数或触发器中不允许显式或隐式提交。 CREATE TABLE语句导致implicit commit,因此在函数中不允许它。
您的代码似乎没有返回任何值(函数体中没有返回语句),您在那里做的事情应该在存储过程中完成,而不是在函数中完成。