sql >> Database >  >> RDS >> Mysql

Tel hoofdletters in String

Probeer deze functie -

DELIMITER $$

CREATE FUNCTION cnt_up_case(str VARCHAR(255))
RETURNS VARCHAR(255)
NOT DETERMINISTIC
CONTAINS SQL
BEGIN

  SET @cnt = 0;
  SET @len = length(str);
  SET @i = 1;

  WHILE @i <= @len
  DO
    SET @c = substring(str, @i, 1);
    IF ascii(@c) > 64 AND ascii(@c) < 91 THEN
      SET @cnt = @cnt + 1;
    END IF;

    SET @i = @i + 1;
  END WHILE;

  RETURN @cnt;
END
$$

DELIMITER ;

Voorbeeld:

SET @Param1 = 'AbCdE';
SET @ResultValue = cnt_up_case(@Param1);
SELECT @ResultValue;
--------------
3


  1. Hoe zoek ik naar Soundex()-substrings in MySQL?

  2. Achtergrondprocessen

  3. Hoe CONCAT_WS() werkt in MariaDB

  4. Monitor SQL Database via SP_WhoIsActive of FogLight | Problemen met SQL Server-prestaties oplossen -1