0

I have a stored procedure where I am passing a CSV list of my values to be inserted into a table by the procedure.

My sp is

DELIMITER $$
USE `btwa`$$
DROP PROCEDURE IF EXISTS `sp_AddRole`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_AddRole`(IN _rolename VARCHAR(50) , IN _permissionList VARCHAR(255))
BEGIN 

        DECLARE _roleId INT;        
        INSERT INTO roles(RoleName, CreatedOn)
            VALUES    (_rolename,CURDATE());            
        SET _roleId = LAST_INSERT_ID();         
        /*INSERT INTO role_permissions(FkRoleId,FKPermissionId)
        VALUES (_roleId, ...);*/here I want to insert values of _permissionList 

END$$
DELIMITER ;

How can I get rows of int from permissionList which I might pass like '1,2,3,4'

I have done development in SQL Server but not much in MySQL.

0

1 Answer 1

1

I were able to done it via help of a forum post at http://www.slickdev.com/2008/09/15/mysql-query-real-values-from-delimiter-separated-string-ids/

My query looks like following

INSERT INTO role_permissions(FkRoleId,FKPermissionId)
        SELECT _roleId, permissionID FROM permissions WHERE FIND_IN_SET(permissionID, _permissionList);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.