我有以下代码让我头疼,我需要为数据库创建这个存储过程,但是,由于“AS”处的语法错误,我可以保存它或实现它。我需要知道我做错了什么?
Create PROCEDURE `insert_delete_update` (OUT
id int,
level varchar(225),
action varchar(20)
)
AS
BEGIN
SET NOCOUNT ON;
IF @Action = 'Insert'
BEGIN
insert into levels (id, level) values(@id, @level)
END
IF @Action = 'Select'
BEGIN
select * from levels
END
IF @Action = 'Update'
BEGIN
UPDATE levels SET
level = @level
WHERE id = @id
END
else IF @Action = 'Delete'
BEGIN
DELETE FROM levels WHERE id = @id
END
END
答案 0 :(得分:0)
是的,所以我终于得到了答案。
以下是最终代码:
CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_delete_update`()
BEGIN
Declare id int;
Declare level varchar(225);
Declare action varchar(20);
Set @Action = 'Insert';
BEGIN
insert into levels (id, level) values(@id, @level);
END;
SET @Action = 'Select';
BEGIN
select * from levels
END ;
SET @Action = 'Update';
BEGIN
UPDATE levels SET
level = @level
WHERE id = @id;
END;
SET @Action = 'Delete';
BEGIN
DELETE FROM levels WHERE id = @id;
END;
END;
END
感谢所有人的帮助!
答案 1 :(得分:-1)
我已经为您编写了存储过程。你可以使用它,我希望它能解决你的问题。我只是从工作台创建的。
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_delete_update`(OUT
id int,
level varchar(225),
action varchar(20))
BEGIN
if @action = 'Insert' THEN
insert into levels (id, level) values(@id, @level) ;
elseif @action = 'Select' THEN
select * from levels ;
elseif @action = 'Update' THEN
UPDATE levels SET
level = @level
WHERE id = @id;
elseif @action = 'Delete' THEN
DELETE FROM levels WHERE id = @id;
end if;
END$$
DELIMITER ;