-1
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_alertpo_items_details ( pomainid_id, `po_item_cod' 在第 14 行

请让我知道我犯的错误?

4

1 回答 1

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
于 2013-09-26T07:14:32.453 回答