本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
INITCAP 函數
將指定字串中每個單字的第一個字母變成大寫。INITCAP 支援 UTF-8 個多位元組字元,每個字元最多四個位元組。
語法
INITCAP(string)
引數
- string
-
CHAR
字串、VARCHAR
字串或隱含評估為CHAR
或VARCHAR
類型的運算式。
傳回類型
VARCHAR
使用須知
INITCAP 函數會讓字串大寫中每個單字的第一個字母,而任何後續字母都會變成 (或左) 小寫。因此,必須了解哪些字元 (除了空白字元) 做為單字分隔符號。單字分隔符號字元是任何非英數字元,包括標點符號、記號及控制字元。以下所有字元都是單字分隔符號:
! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
Tab、新行字元、換頁、換行及歸位也是單字分隔符號。
範例
下列範例使用TICKIT範例資料庫中 CATEGORY和 USERS資料表的資料。如需詳細資訊,請參閱範本資料庫。
若要將CATDESC欄中每個單字的縮寫大寫,請使用下列範例。
SELECT catid, catdesc, INITCAP(catdesc) FROM category ORDER BY 1, 2, 3;
+-------+--------------------------------------------+--------------------------------------------+ | catid | catdesc | initcap | +-------+--------------------------------------------+--------------------------------------------+ | 1 | Major League Baseball | Major League Baseball | | 2 | National Hockey League | National Hockey League | | 3 | National Football League | National Football League | | 4 | National Basketball Association | National Basketball Association | | 5 | Major League Soccer | Major League Soccer | | 6 | Musical theatre | Musical Theatre | | 7 | All non-musical theatre | All Non-Musical Theatre | | 8 | All opera and light opera | All Opera And Light Opera | | 9 | All rock and pop music concerts | All Rock And Pop Music Concerts | | 10 | All jazz singers and bands | All Jazz Singers And Bands | | 11 | All symphony, concerto, and choir concerts | All Symphony, Concerto, And Choir Concerts | +-------+--------------------------------------------+--------------------------------------------+
若要顯示INITCAP函數在未開始單字時不會保留大寫字元,請使用下列範例。例如,字串 MLB
會變成 Mlb
。
SELECT INITCAP(catname) FROM category ORDER BY catname;
+-----------+ | initcap | +-----------+ | Classical | | Jazz | | Mlb | | Mls | | Musicals | | Nba | | Nfl | | Nhl | | Opera | | Plays | | Pop | +-----------+
若要將空格以外的非英數字元顯示為文字分隔符號,請使用下列範例。每個字串中的幾個字母將被大寫。
SELECT email, INITCAP(email) FROM users ORDER BY userid DESC LIMIT 5;
+------------------------------------+------------------------------------+ | email | initcap | +------------------------------------+------------------------------------+ | urna.Ut@egetdictumplacerat.edu | Urna.Ut@Egetdictumplacerat.Edu | | nibh.enim@egestas.ca | Nibh.Enim@Egestas.Ca | | in@Donecat.ca | In@Donecat.Ca | | sodales@blanditviverraDonec.ca | Sodales@Blanditviverradonec.Ca | | sociis.natoque.penatibus@vitae.org | Sociis.Natoque.Penatibus@Vitae.Org | +------------------------------------+------------------------------------+