DELIMITER $$
CREATE
PROCEDURE `cheque_alert`.`SavePoData`(IN poNo VARCHAR(25),IN releaseOrderDate DATE,IN expiryDate DATE,IN enteredDateTime DATETIME,IN enteredBy VARCHAR(8) ,
IN poItemCode VARCHAR(25),IN poItemsId CHAR(1),IN poItemDescription VARCHAR(75),IN quantity DOUBLE,IN amount DOUBLE
)
BEGIN
SELECT CASE WHEN ((SELECT 1 FROM `cheque_alert`.`po_main` WHERE po_no=poNo)>0)
THEN
INSERT INTO `cheque_alert`.`po_items_details`
(`pomainid_id`,
`po_item_code`,
`po_items_id`,
`po_item_description`,
`quantity`,
`amount`)
VALUES ((SELECT id FROM `cheque_alert`.`po_main` WHERE po_no =poNo),
poItemCode,poItemsId,poItemDescription,quantity,amount)
ELSE
INSERT INTO `cheque_alert`.`po_main`
(`po_no`,
`release_order_date`,
`expiry_date`,
`entered_date_time`,
`entered_by`)
VALUES (poNo,releaseOrderDate,expiryDate,enteredDateTime,(SELECT ID FROM cheque_alert.user_login WHERE USER_ID=enteredBy));
INSERT INTO `cheque_alert`.`po_items_details`
(`pomainid_id`,
`po_item_code`,
`po_items_id`,
`po_item_description`,
`quantity`,
`amount`)
VALUES ((SELECT LAST_INSERT_ID(),
poItemCode,
poItemsId,
poItemDescription,
quantity,
amount);
END;
END$$
DELIMITER ;
产生错误:
错误代码:1064
您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在'INTO
cheque_alert
附近使用正确的语法。po_items_details
(pomainid_id
, 第14行的'po_item_cod'
请让我知道我所犯的错误?
答案 0 :(得分:0)
IF-ELSE结构应该是这样的:
IF(some query to check something) THEN
BEGIN
insert something
END
ELSE
BEGIN
insert something
insert something else
END
同时CASE只会定义一些值,而不是整个查询。例如:
SELECT CASE name WHEN 'hamburger' THEN 'unhealthy' ELSE 'healthy' END
FROM food