• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

MySQL Command: TRIM()

December 20, 2023

MySQL Command: TRIM()

MySQL is a popular open-source relational database management system that provides various functions to manipulate and transform data. One such function is TRIM(), which is used to remove specified characters from the beginning and/or end of a string. In this article, we will explore the usage and syntax of the TRIM() command in MySQL.

Syntax

The syntax for the TRIM() command in MySQL is as follows:

TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str)

The TRIM() function takes a string str as input and removes the specified characters from the beginning and/or end of the string. The optional BOTH, LEADING, or TRAILING keywords determine which part of the string to trim. The optional remstr parameter specifies the characters to be removed. If not specified, the default is to remove spaces.

Examples

Let’s look at some examples to understand how the TRIM() command works:

Example 1: TRIM() with default parameters

In this example, we will remove leading and trailing spaces from a string:

SELECT TRIM('  Hello World  ');

The output of this query will be:

Hello World

The TRIM() function removes the leading and trailing spaces from the string ‘ Hello World ‘ and returns ‘Hello World’.

Example 2: TRIM() with specified characters

In this example, we will remove the characters ‘abc’ from the beginning and end of a string:

SELECT TRIM(BOTH 'abc' FROM 'abcHello Worldabc');

The output of this query will be:

Hello World

The TRIM() function removes the characters ‘abc’ from both the beginning and end of the string ‘abcHello Worldabc’ and returns ‘Hello World’.

Example 3: TRIM() with leading characters

In this example, we will remove leading zeros from a string:

SELECT TRIM(LEADING '0' FROM '000123');

The output of this query will be:

123

The TRIM() function removes the leading zeros from the string ‘000123’ and returns ‘123’.

Conclusion

The TRIM() command in MySQL is a useful function for removing specified characters from the beginning and/or end of a string. It provides flexibility by allowing you to choose which part of the string to trim and which characters to remove. By understanding and utilizing the TRIM() command effectively, you can manipulate and clean up your data in MySQL.

Summary

In summary, the TRIM() command in MySQL is used to remove specified characters from the beginning and/or end of a string. It provides flexibility by allowing you to choose which part of the string to trim and which characters to remove. To learn more about VPS hosting solutions, visit Server.HK.

Recent Posts

  • VPS Hosting vs Shared Hosting: Why the Upgrade Is Worth It for Asia-Facing Websites
  • Hong Kong VPS vs Google Cloud Asia: Which Delivers Better China Performance in 2026?
  • Why No-ICP-Filing Hong Kong Hosting Is the Smart Choice for Cross-Border E-Commerce
  • Hong Kong VPS vs AWS Hong Kong Region: Cost, Latency, and Control Compared
  • Data Privacy Laws in Hong Kong: What VPS Users Need to Know

Recent Comments

  1. linezolid cost oral on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  2. metoprolol generic on Hong Kong VPS vs Japan VPS: Head-to-Head for Asia-Pacific Deployments in 2026
  3. levitra price on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  4. finasterid on Hong Kong VPS vs Singapore VPS: Which Is Better for Your Asia Business in 2026?
  5. doxycycline hyclate 100mg on How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot