,

Huruf Besar di Setiap Kata (MySQL Function)

You are viewing an old revision of this post, from January 5, 2019 @ 20:58:22. See below for differences between this version and the current revision.

Halo sahabat Ayo Belajar Komputer, ini salah satu kumpulan tips function di MySQL, bagaimana caranya agar setiap kata diawali dengan Huruf Besar.

Ok, langsung aja ya. By the way, tinggal copy paste di terminal mysql/SQL Editor/Query Editor dan modify sendiri ya nama function-nya (nama function dibawah adalah initcap).

CREATE FUNCTION initcap(input VARCHAR(255))
RETURNS VARCHAR(255)
DETERMINISTIC
BEGIN
DECLARE len INT;
DECLARE i INT;
SET len = CHAR_LENGTH(input);
SET input = LOWER(input);
SET i = 0;

WHILE (i < len) DO
IF (MID(input,i,1) = ' ' OR i = 0) THEN
IF (i < len) THEN
SET input = CONCAT(
LEFT(input,i),
UPPER(MID(input,i + 1,1)),
RIGHT(input,len - i - 1)
);
END IF;
END IF;
SET i = i + 1;
END WHILE;
RETURN input;
END;

Cara gunaiinya bagaimana ?, ya sama seperti menjalankan fungsi query default lainnya.

SELECT initcap('ini adalah Tulisan');
hasilnya :
Ini Adalah Tulisan

Nah sekilan dulu ya sobat Ayo Belajar Komputer tips yang mungkin sewaktu waktu bisa digunakan 🙂

Post Revisions:

Changes:

There are no differences between the January 5, 2019 @ 20:58:22 revision and the current revision. (Maybe only post meta information was changed.)

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *