DEV Community

Michael
Michael

Posted on • Originally published at gbase8.cn

GBase 8a initcap: Capitalizing the First Letter of Every Word

The initcap function in GBase 8a capitalizes the first letter of each word in a string and converts the rest to lowercase. It's a handy tool for normalising names, titles, and other text fields in a gbase database.

Syntax

INITCAP(expr)
Enter fullscreen mode Exit fullscreen mode
  • expr: a string expression — a column, a literal, or a function result.
  • Letters are determined by the Unicode Letter category, covering English, pinyin, Chinese characters, Japanese kana, and Western European letters.
  • Words are delimited by spaces, tabs, newlines, full‑width spaces, and punctuation marks (commas, hyphens, underscores, etc.).

Examples

Basic English Text

gbase> SELECT INITCAP('hello wORLD');
+------------------------+
| INITCAP('hello wORLD') |
+------------------------+
| Hello World            |
+------------------------+
Enter fullscreen mode Exit fullscreen mode

Full‑Width Pinyin

Full‑width letters are treated the same way.

gbase> SELECT INITCAP('abc');
+----------------------+
| INITCAP('abc')    |
+----------------------+
| Abc               |
+----------------------+
Enter fullscreen mode Exit fullscreen mode

Various Delimiters

initcap recognises a wide range of separators, so words split by punctuation, hyphens, underscores, or full‑width spaces are each capitalised independently.

gbase> SELECT INITCAP('hello,wORLD');
+------------------------+
| INITCAP('hello,wORLD') |
+------------------------+
| Hello,World            |
+------------------------+

gbase> SELECT INITCAP('hello-wORLD');
+------------------------+
| INITCAP('hello-wORLD') |
+------------------------+
| Hello-World            |
+------------------------+

gbase> SELECT INITCAP('hello_wORLD');
+------------------------+
| INITCAP('hello_wORLD') |
+------------------------+
| Hello_World            |
+------------------------+
Enter fullscreen mode Exit fullscreen mode

initcap is a simple yet powerful string formatting function in GBase 8a. Use it whenever you need to present text in a consistent, capitalised format directly within your SQL queries.

Top comments (0)