MySql存储过程 [英] MySql Stored Procedure
问题描述
我正在为MySql中的Insert和Select数据创建存储过程,我的存储过程是 -
DELIMITER $$
CREATE DEFINER =`root` @`localhost` PROCEDURE `new_procedure`(_ action varchar ( 10 ),文件 varchar ( 100 ))
BEGIN
if _action = ' INSERT' 然后
插入 进入 tab_file(文件)值(文件);
end if ;
如果 _action = ' select' 然后
选择 ID,文件 来自 tab_file;
end if ;
END
使用此存储过程,我可以插入数据,但是选择查询不起作用。它给出的错误如预期2,得到1请帮我如何在mysql中编写存储过程来选择,插入,更新和删除脚本?
谢谢
CREATE DEFINER =`root` @`localhost` PROCEDURE `new_procedure`(_ action varchar ( 10 ),文件 varchar ( 100 ))
BEGIN
< span class =code-keyword> if _action = ' INSERT' 然后
插入 进入 tab_file(文件)值(文件);
end if ;
如果 _action = ' select' 然后
选择 ID,文件 来自 tab_file;
end if ;
END使用此存储过程,我可以插入数据,但是选择查询不起作用。它给出的错误如预期2,得到1请帮我如何在mysql中编写存储过程来选择,插入,更新和删除脚本?
谢谢
我不确定关于你的错误,但你可以将你的参数名称替换为File to,ex FileName吗?
我看到File也是你的表的列名,所以select语句可能做错了吗?
Hi, I am creating a stored procedure for Insert and Select data in MySql , my stored procedure is -
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `new_procedure`(_action varchar(10) ,File varchar(100))
BEGIN
if _action = 'INSERT' then
insert into tab_file (File) values (File);
end if;
if _action = 'select' then
select ID,File from tab_file;
end if;
END
With this stored procedure i am able to insert data but select query is not working.It is giving error like "Expected 2,got 1" Please help me how to write stored procedure in mysql for select, insert, update and delete scripts?
Thanks
CREATE DEFINER=`root`@`localhost` PROCEDURE `new_procedure`(_action varchar(10) ,File varchar(100)) BEGIN if _action = 'INSERT' then insert into tab_file (File) values (File); end if; if _action = 'select' then select ID,File from tab_file; end if; ENDWith this stored procedure i am able to insert data but select query is not working.It is giving error like "Expected 2,got 1" Please help me how to write stored procedure in mysql for select, insert, update and delete scripts?
Thanks
I'm not sure about your error, but can you replace your parameter name from File to, ex FileName?
I saw File is also a column name of your table, so the select statement could do something wrong?
这篇关于MySql存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!