我試圖創建一個存儲過程來插入或更新基於輸入變量的記錄。但是,當我嘗試編譯SP時,只會告訴我以下內容:代碼1064,您的SQL語法中有錯誤,請檢查與您的MySQL服務器版本相對應的手冊,以獲取在80行附近使用的正確語法。我還沒有找到解決方案。非常感謝你給我的任何幫助。在Mysql中創建插入更新的存儲過程
我的SP代碼如下:
DELIMITER $$
CREATE PROCEDURE `sp_sertup`(IN i_operation CHAR(1),
IN i_system VARCHAR(20),
IN i_subsystem VARCHAR(20),
IN i_ref VARCHAR(20),
IN i_significance VARCHAR(20),
IN i_rank VARCHAR(20),
IN i_implication VARCHAR(20),
IN i_loc1 VARCHAR(20),
IN i_loc2 VARCHAR(20),
IN i_task VARCHAR(20),
IN i_time VARCHAR(20),
IN i_cost1 VARCHAR(20),
IN i_cost2 VARCHAR(20),
IN i_note VARCHAR(20),
IN i_attach VARCHAR(20),
IN i_operation_text VARCHAR(20),
IN i_id_setup INT)
BEGIN
IF (i_operation = 'I') THEN
UPDATE setup_gs SET setup_status = 0 WHERE id_setup = id_setup;
INSERT INTO setup_gs(
SystemLabel,
SubsystemLabel,
RefLabel,
SignificanceLabel,
RankLabel,
ImplicationLabel,
Location1Label,
Location2Label,
TaskLabel,
TimeLabel,
Cost1Label,
Cost2Label,
NoteLabel,
attachmentText,
OperationsText,
setup_status
)
VALUES
(
i_system,
i_subsystem,
i_ref,
i_significance,
i_rank,
i_implication,
i_loc1,
i_loc2,
i_task,
i_time,
i_cost1,
i_cost2,
i_note,
i_attach,
i_operation_text,
1);
IF (i_operation = 'U') THEN
UPDATE
setup_gs
SET
SystemLabel = values(i_system),
SubsystemLabel = values(i_subsystem),
RefLabel = values(i_ref),
SignificanceLabel = values(i_significance),
RankLabel = values(i_rank),
ImplicationLabel = values(i_implication),
Location1Label = values(i_loc1),
Location2Label = values(i_loc2),
TaskLabel = values(i_task),
TimeLabel = values(i_time),
Cost1Label = values(i_cost1),
Cost2Label = values(i_cost2),
NoteLabel = values(i_note),
attachmentText = values(i_attach),
OperationsText = values(i_operation_text),
setup_status = 1
WHERE id_setup = i_id_setup;
END $$
DELIMITER ;
Wao,那簡單,非常感謝,非常完美。我有幾個小時在這附近徘徊。你星期六救了我! – oraguilinux
NP,歡迎來到SO!如果您同意,請記住投票給您喜歡的任何答案,並在最好的答案上檢查該答案。 –