Click here to Skip to main content
15,936,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am creating a stored procedure for Insert and Select data in MySql , my stored procedure is -
SQL
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
Posted
Updated 4-Jul-13 18:28pm
v3
Comments
Sudhakar Shinde 5-Jul-13 0:36am    
Use google to find out several tutorials/examples required by you.
rachayita@Next 5-Jul-13 0:41am    
I am new in MySql and i have checked on gogle a lot but am not getting.

1 solution

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?
 
Share this answer
 
Comments
rachayita@Next 5-Jul-13 0:54am    
I have tried this also but same error i am getting.
thanh_bkhn 5-Jul-13 1:05am    
What is exactly error message you got?
Member 10895951 5-Mar-15 3:17am    
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `new_procedure`(_action varchar(10) ,abc varchar(100))
BEGIN
if _action = 'INSERT' then
insert into tab_file (File) values (abc);
end if;
if _action = 'select' then
select ID,File from tab_file;
end if;
END


Change your parameter and column value as abc instead of the column name .
becuase your select command is getting the parameter values.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900