/* COUNT LEVEL ONE MEDICINE RISKS LINKED TO A USER */
/* =============================================================================================================== */
DROP FUNCTION IF EXISTS COUNT_MEDICINE_RISK_LEVEL_ONES;
COMMIT;

DELIMITER //

CREATE FUNCTION `COUNT_MEDICINE_RISK_LEVEL_ONES`(`p_list` VARCHAR(555))
RETURNS INT
NOT DETERMINISTIC
BEGIN

	DECLARE iCount INT DEFAULT 0;

  SELECT CHAR_LENGTH(
    REPLACE(
      REPLACE(
        REPLACE(
          REPLACE(
            REPLACE(
              REPLACE(
                REPLACE(
                  P_LIST, ' ', ''
                ), ',', ''
              ), '2', ''
            ), '3', ''
          ), '4', ''
        ), '5', ''
      ), '6', ''
    )
  )
  INTO iCount;
	
	RETURN iCount;

END 
//
COMMIT //

DELIMITER ;
