我的语法只适用于单个IF语句,然后我决定检查ISBN是否已经存在,如果确实存在,则只返回“已存在”
我正在使用“功能”
这是我已经尝试过的。
IF EXISTS(SELECT ISBN FROM book WHERE ISBN=i) THEN
RETURN "Book already exists.";
ELSE
IF (b=0)
THEN
INSERT INTO book(ISBN,title,author,publisher,Date_Published,`Cost`) VALUES(i,t,a,p,STR_TO_DATE(d, '%M %e,%Y'),c);
RETURN "Book has been successfully added.";
ELSE
UPDATE book SET ISBN=i, title=t,author=a,publisher=p,Date_Published=d,cost=c WHERE bookID=b;
RETURN "Book has been successfully altered.";
END IF;
答案 0 :(得分:1)
试试这样:
IF EXISTS(SELECT ISBN FROM book WHERE ISBN=i) THEN
RETURN "Book already exists.";
ELSEIF (b=0) THEN
INSERT INTO book(ISBN,title,author,publisher,Date_Published,`Cost`)
VALUES(i,t,a,p,STR_TO_DATE(d, '%M %e,%Y'),c);
RETURN "Book has been successfully added.";
ELSE
UPDATE book SET ISBN=i,
title=t,author=a,publisher=p,Date_Published=d,cost=c
WHERE bookID=b;
RETURN "Book has been successfully altered.";
END IF;
(您需要删除ELSE IF之间的空格)