trim Function (2024)

The trim function enables you to trim leading or trailing characters (or both) from a string.

Syntax

returnvalue trim(source [, position [, trim_character]])source ::= any*position ::= "leading"|"trailing"|"both"trim_character ::= string*returnvalue ::= string

Semantics

source

The input string that should be trimmed. This argument is implicitly cast to a sequence of strings.

If you provide only the source argument, then the leading and trailing blank spaces are removed.

position

This argument indicates whether leading or trailing or both leading and trailing characters should be removed. The following are the valid values that can be specified for this argument.

  • If leading is specified, then the characters equal to the trim_character argument are removed from the beginning of the string.
  • If trailing is specified, then the characters equal to the trim_character argument are removed at the end of the string.
  • If both is specified, then the characters equal to the trim_character argument are removed from both the beginning and end of the string.
  • If no value is specified, then both value is assumed.
  • If any value other than the above valid values are specified, then NULL is returned.
trim_character

This argument specifies the characters that should be removed from the source string. If you do not specify this argument, then a blank space is taken as the default value.

Only one character is allowed for this argument. If there are more than one character, then the first character will be used.

If an empty string is specified, then no trimming happens.

return_value

Returns NULL if any of the arguments is NULL.

Returns NULL if any argument is an empty sequence or a sequence with more than one item.

Example 12-9 trim function

Create this table and insert values in it to run the trim, ltrim, and rtrim function examples.

CREATE TABLE trim_demo ( id INTEGER, name STRING, yearofbirth STRING, PRIMARY KEY (id));INSERT INTO trim_demo VALUES (10, " Peter ", 1980);INSERT INTO trim_demo VALUES (20, "Mary", 1973);INSERT INTO trim_demo VALUES (30, " Oliver", 2000);INSERT INTO trim_demo VALUES (40, "John ", 2000);SELECT * FROM trim_demo;
 +----+-----------+-------------+ | id | name | yearofbirth | +----+-----------+-------------+ | 10 | Peter | 1980 | | 20 | Mary | 1973 | | 30 | Oliver | 2000 | | 40 | John | 2000 | +----+-----------+-------------+

Example 12-10 trim Function

In this example, the id and yearofbirth are selected from the trim_demo table. Notice that the zeros at the end of the yearofbirth are removed using the trim function.

SELECT id, trim(yearofbirth,"trailing",'0') FROM trim_demo;
 +----+----------+ | id | Column_2 | +----+----------+ | 10 | 198 | | 20 | 1973 | | 30 | 2 | | 40 | 2 | +----+----------+

Example 12-11 trim Function

In this example, '19' is provided as the trim_character. However, as per semantics, only the first character '1' will be considered for trimming.

SELECT id, trim(yearofbirth,"leading",'19') FROM trim_demo;
 +----+----------+ | id | Column_2 | +----+----------+ | 10 | 980 | | 20 | 973 | | 30 | 2000 | | 40 | 2000 | +----+----------+
trim Function (2024)
Top Articles
Having Faith During a Financial Crisis
Filecoin (FIL) Price Prediction: 2024, 2025, 2026 - 2030
No Hard Feelings Showtimes Near Metropolitan Fiesta 5 Theatre
Canary im Test: Ein All-in-One Überwachungssystem? - HouseControllers
Wild Smile Stapleton
Nwi Police Blotter
Call of Duty: NEXT Event Intel, How to Watch, and Tune In Rewards
2021 Tesla Model 3 Standard Range Pl electric for sale - Portland, OR - craigslist
Cincinnati Bearcats roll to 66-13 win over Eastern Kentucky in season-opener
Degreeworks Sbu
Sport Clip Hours
Programmieren (kinder)leicht gemacht – mit Scratch! - fobizz
David Turner Evangelist Net Worth
Truck Toppers For Sale Craigslist
7440 Dean Martin Dr Suite 204 Directions
What is Cyber Big Game Hunting? - CrowdStrike
Mills and Main Street Tour
Unity - Manual: Scene view navigation
Curry Ford Accident Today
Exterior insulation details for a laminated timber gothic arch cabin - GreenBuildingAdvisor
Samantha Aufderheide
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Elite Dangerous How To Scan Nav Beacon
Weather October 15
Where to eat: the 50 best restaurants in Freiburg im Breisgau
Mawal Gameroom Download
Eegees Gift Card Balance
Mastering Serpentine Belt Replacement: A Step-by-Step Guide | The Motor Guy
Primerica Shareholder Account
Six Flags Employee Pay Stubs
Lil Durk's Brother DThang Killed in Harvey, Illinois, ME Confirms
Cheap Motorcycles Craigslist
Uhaul Park Merced
How Much Is Mink V3
Why Holly Gibney Is One of TV's Best Protagonists
Pitchfork's Top 200 of the 2010s: 50-1 (clips)
7543460065
How to play Yahoo Fantasy Football | Yahoo Help - SLN24152
Spectrum Outage in Genoa City, Wisconsin
9 oplossingen voor het laptoptouchpad dat niet werkt in Windows - TWCB (NL)
Www.craigslist.com Waco
Unitedhealthcare Community Plan Eye Doctors
Matt Brickman Wikipedia
Ihop Deliver
Model Center Jasmin
Maurices Thanks Crossword Clue
De Donde Es El Area +63
Ret Paladin Phase 2 Bis Wotlk
Gainswave Review Forum
Latest Posts
Article information

Author: Arline Emard IV

Last Updated:

Views: 6412

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Arline Emard IV

Birthday: 1996-07-10

Address: 8912 Hintz Shore, West Louie, AZ 69363-0747

Phone: +13454700762376

Job: Administration Technician

Hobby: Paintball, Horseback riding, Cycling, Running, Macrame, Playing musical instruments, Soapmaking

Introduction: My name is Arline Emard IV, I am a cheerful, gorgeous, colorful, joyous, excited, super, inquisitive person who loves writing and wants to share my knowledge and understanding with you.