Question

Hi im trying to insert using this sp with insert statment of:

call insertuser (1, '077788899965', 'Digest 1.0', ':=', 'asjdfhiuoadshgiadufg');

SP CODE:

DELIMITER$$

CREATE PROCEDURE insertuser (IN IdParam INT, IN UserNameParam varchar(64), IN AttributeParam varchar(64), IN OpParam  char(2), IN ValueParam varchar(253)) 
BEGIN 

    // Delete user if they already exist

    DELETE FROM radcheck 
    WHERE username = UserNameParam; 

    // Insert

    INSERT INTO  radcheck (id, username, atrribute, op, value) 
    SELECT (IdParam, UserNameParam, AttributeParam, OpParam, ValueParam); 

END$$

But I am getting error of:

ERROR 1241 (21000): Operand should contain 1 column(s)

Any idea how to resolve this?

Was it helpful?

Solution

DELIMITER $$

CREATE PROCEDURE insertuser (IN IdParam INT, IN UserNameParam varchar(64), 
                             IN AttributeParam varchar(64), IN OpParam  char(2), 
                             IN ValueParam varchar(253)) 
BEGIN 
    DELETE FROM radcheck 
    WHERE username = UserNameParam; 

    INSERT INTO  radcheck (id, username, atrribute, op, `value`) 
    SELECT IdParam, UserNameParam, AttributeParam, OpParam, ValueParam;
END
$$

There were 2 problems:

  • missing space after DELIMITER
  • // is not a comment start in MySQL. Use /* */

If you use a SQL IDE like MySQL Workbench such errors will be highlighted and are easier to fix.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top