MySQL 查詢如何將小寫字母轉換為大寫字母?
您可以使用 MySQL 的內建函式 UPPER() 將小寫字母轉換為大寫字母。語法如下所示,帶有 select 語句。
SELECT UPPER(‘yourStringValue’);
以下是一個顯示小寫字串的示例:
mysql> select upper('john');
以下是顯示大寫字串的輸出:
+---------------+ | upper('john') | +---------------+ | JOHN | +---------------+ 1 row in set (0.00 sec)
如果您已經有一個包含小寫值的表,則可以將 UPPER() 函式與 update 命令一起使用。語法如下:
UPDATE yourTableName set yourColumnName = UPPER(yourColumnName);
為了理解上述概念,讓我們首先建立一個表並在其中插入小寫字串值。以下是建立表的查詢:
mysql> create table UpperTableDemo −> ( −> BookName longtext −> ); Query OK, 0 rows affected (0.70 sec)
使用 INSERT 命令在表中插入一些記錄。查詢如下:
mysql> insert into UpperTableDemo values('introduction to c'); Query OK, 1 row affected (0.13 sec) mysql> insert into UpperTableDemo values('introduction to java'); Query OK, 1 row affected (0.18 sec) mysql> insert into UpperTableDemo values('introduction to python'); Query OK, 1 row affected (0.11 sec) mysql> insert into UpperTableDemo values('introduction to c#'); Query OK, 1 row affected (0.17 sec)
使用 select 語句顯示錶中的所有記錄。查詢如下:
mysql> select *from UpperTableDemo;
以下是輸出:
+------------------------+ | BookName | +------------------------+ | introduction to c | | introduction to java | | introduction to python | | introduction to c# | +------------------------+ 4 rows in set (0.00 sec)
以下是將小寫字母轉換為大寫字母的查詢:
mysql> update UpperTableDemo set BookName = upper(BookName); Query OK, 4 rows affected (0.16 sec) Rows matched: 4 Changed: 4 Warnings: 0
再次顯示所有記錄以及更新後的值。查詢如下:
mysql> select *from UpperTableDemo;
以下是輸出:
+------------------------+ | BookName | +------------------------+ | INTRODUCTION TO C | | INTRODUCTION TO JAVA | | INTRODUCTION TO PYTHON | | INTRODUCTION TO C# | +------------------------+ 4 rows in set (0.00 sec)
廣告