 | | | | |  | | | | | Guest | 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$$ | | | | | | | | Guest | 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$$ | | | | | | | | Guest | Re: Stored Procedures: INSERT VALUES string as a parameter -
06-04-2007, 07:58 AM
Thanks, subtenante..
Sorry for being such an idiot... | | | | | | | | Guest | 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. | | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | |  |