0

I am creating a small (for now) stored procedure to insert some data. When I create this I get an error.

DROP PROCEDURE IF EXISTS InsertTESTData;
delimiter $$
CREATE PROCEDURE InsertTESTData (
p_pink_no VARCHAR,
p_carrier VARCHAR,
p_thisno INT
)
BEGIN
INSERT INTO RefDB (pink_no,carrier,thisno) 
    VALUES 
(p_pink_no,p_carrier,p_thisno);
END $$
delimiter ;

And the error I always get is a 1064 SQL error as follows.

Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'p_carrier VARCHAR,p_thisno IN) BEGIN INSERT INTO RefDB (pink_no,carrier,t' at line 2

I thought I had everything covered and am now pulling my hair out!

2 Answers 2

0

You need to define a length for your varchar parameters like this

p_pink_no VARCHAR(100)

and change

p_thisno IN

to

p_thisno INT

Complete example:

DROP PROCEDURE IF EXISTS InsertTESTData;
delimiter $$
CREATE PROCEDURE InsertTESTData (
    p_pink_no VARCHAR(100),
    p_carrier VARCHAR(100),
    p_thisno INT)
BEGIN
    INSERT INTO RefDB (pink_no,carrier,thisno) 
    VALUES (p_pink_no,p_carrier,p_thisno);
END $$
delimiter ;
2
  • Sorry the second one was a typo on my part when pasting into SO. Adding the length has not made a difference and still get the same error Jul 2, 2012 at 9:49
  • I just added the IN parameter to the beginning of all values and now it is working! Strange as I thought this was default? Jul 2, 2012 at 9:51
-1

you have to declare the size of the data type ,after thal i am sure your code will be execute successfully. follow this

DROP PROCEDURE IF EXISTS InsertTESTData;
delimiter $$
CREATE PROCEDURE InsertTESTData (
    p_pink_no VARCHAR(20),
    p_carrier VARCHAR(200),
    p_thisno number(23))
BEGIN
    INSERT INTO RefDB (pink_no,carrier,thisno) 
    VALUES (p_pink_no,p_carrier,p_thisno);
END $$
delimiter ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.