Go Back   Forum Care Forums > Development Reference Area > MySQL Discussion

Reply
 
LinkBack Thread Tools Display Modes
Stored Procedures: INSERT VALUES string as a parameter
Old
  (#1)
Guest
Guest
 
Posts: n/a
Default Stored Procedures: INSERT VALUES string as a parameter - 06-04-2007, 07:58 AM

How can I get this stored procedure to work?
I want to p*** all the INSERT parameters as one string.

/*I want this to insert 2 records*/
DROP PROCEDURE IF EXISTS spTest$$
CREATE PROCEDURE spTest()
BEGIN
DECLARE pVal TEXT;
SET pVal = "('a','b','c','d','e','f'),
('g','h','i','j','k','l')";
INSERT INTO test (fld1,fld2,fld3,fld4,fld5,fld6)
VALUES pVal;
END$$

/*I've tried prepared statements as well without success*/
DROP PROCEDURE IF EXISTS glTest$$
CREATE PROCEDURE glTest()
BEGIN
PREPARE ps FROM "INSERT INTO test
(fld1,fld2,fld3,fld4,fld5,fld6) VALUES ?";
SET @p = "('a','b','c','d','e','f'),('g','h','i','j','k','l ')";
EXECUTE ps USING @p;
END$$

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Stored Procedures: INSERT VALUES string as a parameter
Old
  (#2)
subtenante
Guest
 
Posts: n/a
Default Re: Stored Procedures: INSERT VALUES string as a parameter - 06-04-2007, 07:58 AM

On 25 May 2007 23:31:00 -0700, EMAIL REMOVED wrote:

>/*I want this to insert 2 records*/
>DROP PROCEDURE IF EXISTS spTest$$
>CREATE PROCEDURE spTest()
>BEGIN
> DECLARE pVal TEXT;
> SET pVal = "('a','b','c','d','e','f'),
>('g','h','i','j','k','l')";
> INSERT INTO test (fld1,fld2,fld3,fld4,fld5,fld6)
> VALUES pVal;
>END$$
>
>/*I've tried prepared statements as well without success*/
>DROP PROCEDURE IF EXISTS glTest$$
>CREATE PROCEDURE glTest()
>BEGIN
> PREPARE ps FROM "INSERT INTO test
>(fld1,fld2,fld3,fld4,fld5,fld6) VALUES ?";
> SET @p = "('a','b','c','d','e','f'),('g','h','i','j','k','l ')";
> EXECUTE ps USING @p;
>END$$


BEGIN

DECLARE _insert TEXT;
DECLARE _vars TEXT;

SET _insert = 'INSERT INTO Languages
(`LangID`,`LangCode`,`LangStatus`,`TxtlID`) VALUES ';
SET _vars = "(NULL,'CN','10','1'),(NULL,'EL','10','10')";

SET @insert = CONCAT(_insert,_vars);
PREPARE ps FROM @insert;
EXECUTE ps;

END$$
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Stored Procedures: INSERT VALUES string as a parameter
Old
  (#3)
Guest
Guest
 
Posts: n/a
Default Re: Stored Procedures: INSERT VALUES string as a parameter - 06-04-2007, 07:58 AM

Thanks, subtenante..
Sorry for being such an idiot...

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Stored Procedures: INSERT VALUES string as a parameter
Old
  (#4)
subtenante
Guest
 
Posts: n/a
Default Re: Stored Procedures: INSERT VALUES string as a parameter - 06-04-2007, 07:58 AM

On 28 May 2007 14:55:38 -0700, EMAIL REMOVED wrote:

>Thanks, subtenante..
>Sorry for being such an idiot...


Well I don't think you are. At first I tried to fix your USING problem
but I couldn't, so I picked the good old 'CONCAT everything and run'
strategy.
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




Contact Us - Forum Care Forums - Archive - Top