Different types of Netezza Trim Functions and Examples

  • Post author:
  • Post last modified:February 27, 2018
  • Post category:Netezza
  • Reading time:3 mins read

The Netezza TRIM functions which are available in Netezza NZSQL are used to remove specified prefix or suffix from a string. The most common pattern being removed is white spaces.

netezza trim functions

Netezza support different trim function that you can be used to trim or remove the particular character or white spaces. A Netezza trim functions includes TRIM, LTRIM, and RTRIM.

Read:

Different types of Netezza Trim Functions

There are different types Netezza TRIM functions:

Netezza TRIM

TRIM function removes leading or trailing occurrences of characters from a string.

Netezza TRIM Syntax:

trim( {leading | trailing | both} [<character> | ‘ ‘ ] from {<character-value>});

Netezza TRIM Examples

TRAINING.ADMIN(ADMIN)=> select trim( leading from ' abc ' );
 LTRIM
-------
 abc
(1 row)

TRAINING.ADMIN(ADMIN)=> select trim( trailing from ' abc ' );
 RTRIM
--------
 abc
(1 row)

TRAINING.ADMIN(ADMIN)=> select trim( leading 'a' from 'aabc ' );
 LTRIM
-------
 bc
(1 row)

TRAINING.ADMIN(ADMIN)=> select trim( trailing 'e' from 'aabceeee' );
 RTRIM
-------
 aabc
(1 row)

TRAINING.ADMIN(ADMIN)=> select trim( both 'a' from 'aabceeeeaa' );
 BTRIM
--------
 bceeee
(1 row)

TRAINING.ADMIN(ADMIN)=>

Netezza LTRIM

This function Trims spaces from left end of the given string. This function also trims occurrences of the characters in t string from left end of string s.

Netezza LTRIM Syntax:

ltrim(s);
ltrim(s,t);

Netezza LTRIM Examples

TRAINING.ADMIN(ADMIN)=> select ltrim(' abcd');
 LTRIM
-------
 abcd
(1 row)

TRAINING.ADMIN(ADMIN)=> select ltrim('abcd','a');
 LTRIM
-------
 bcd
(1 row)

Netezza RTRIM

This function Trims spaces from right end of the given string. This function also trims occurrences of the characters in t string from right end of string s.

Netezza RTRIM Syntax:

rtrim(s);
rtrim(s,t);

Netezza RTRIM Examples

TRAINING.ADMIN(ADMIN)=> select rtrim('abcd ');
 RTRIM
-------
 abcd
(1 row)

TRAINING.ADMIN(ADMIN)=> select rtrim('abcd','d');
 RTRIM
-------
 abc
(1 row)