mysql query execuation

Last Reply 9 days ago By dharmendr

Posted 9 days ago

Hi all

I have My sql sp for insert And update

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_newemp21`(
    in empid int,
    in empname varchar(500),
    in empaddress varchar(500), 
    in emplocation varchar(500))
BEGIN
if (empid is  null)
    then INSERT INTO  newemp21(empname,empaddress,emplocation) VALUES(empname,empaddress,emplocation);  
else 
    update newemp21 set empname=empname, empaddress=empaddress, emplocation=emplocation where empid=empid;
END IF;
End

it is giveing error as when i try to insert the data without 

empid when i call the Sp  like call test1.sp_newemp21('ram','goa','goa');

it is says like u have to Supplies the 3 Arguments, it need 4 paramaters

You are viewing reply posted by: dharmendr 9 days ago.
Posted 9 days ago

Hi,

Your procedure expects 4 parameters empid, empname, empaddress, emplocation.

But you are passing only empname, empaddress, emplocation.

You have to pass empid parameter or make the empid nullable and pass null as parameter.

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_newemp21`(
    in empid int DEFAULT NULL,
    in empname varchar(500),
    in empaddress varchar(500),
    in emplocation varchar(500))
BEGIN
if (empid is  null)
    then INSERT INTO  newemp21(empname,empaddress,emplocation) VALUES(empname,empaddress,emplocation); 
else
    update newemp21 set empname=empname, empaddress=empaddress, emplocation=emplocation where empid=empid;
END IF;
End

Then call it

sp_newemp21(null,'ram','goa','goa')