DB2 Tutorial

  • Home
  • Start Here
  • Basics
  • Views
  • Triggers
  • Indexes
  • Functions
    • Aggregate Functions
    • Date Functions
    • String Functions
    • Window Functions
Home » Db2 String Functions » Db2 RTRIM

Db2 RTRIM

Summary: in this tutorial, you will learn how to use the Db2 RTRIM() function to remove specific characters from the end of a string.

Db2 RTRIM() function overview

Here is the basic syntax RTRIM() function:

RTRIM(input_string, [trim_string])

The RTRIM() function removes all characters contained in the trim_string from the end of the input_string.

If you skip the trim_string argument, the RTRIM() function will remove the trailing blanks from the input_string.

Note that Db2 uses the binary representation of each character in the trim_string to compare with the bytes at the end of the input_string.

Db2 RTRIM() function examples

Let’s take some examples of using the RTRIM() function.

1) Using Db2 RTRIM() function to remove trailing blanks from a string example

The following example uses the RTRIM() function to remove all the trailing blanks from the string 'Db2 LTRIM ':

SELECT RTRIM('Db2 RTRIM ') result FROM SYSIBM.SYSDUMMY1;

The following is the result set:

RESULT ------------ Db2 RTRIM

2) Using Db2 RTRIM() function to remove a specific string from the end of a string example

This example uses the RTRIM() function to remove the string '123' from the string 'abc123' string:

SELECT RTRIM('abc123','123') result FROM SYSIBM.SYSDUMMY1;

The following illustrates the output:

RESULT ------ abc

In this tutorial, you have learned how to use the Db2 RTRIM() function to remove a specified string from the end of a string.

  • Was this tutorial helpful ?
  • YesNo
Previous Db2 RIGHT
Next Db2 SUBSTRING

Getting Started

  • What is Db2
  • Installing Db2 Database Server
  • Db2 Sample Database
  • Creating a Db2 Sample Database
  • Connecting to a Db2 Database
  • Interacting with Db2 using SQL Developer

Data Manipulation

  • SELECT
  • ORDER BY
  • WHERE
  • SELECT DISTINCT
  • AND
  • OR
  • BETWEEN
  • LIKE
  • IN
  • LIMIT
  • FETCH
  • Join
  • INNER JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • FULL OUTER JOIN
  • Self-Join
  • CROSS JOIN
  • GROUP BY
  • Subquery
  • HAVING
  • UNION
  • INTERSECT
  • EXCEPT
  • Common Table Expression or CTE
  • INSERT
  • INSERT Multiple Rows
  • INSERT INTO SELECT
  • UPDATE
  • DELETE

Managing Database Objects

  • CREATE TABLE
  • Identity Columns
  • ALTER COLUMN
  • ADD COLUMN
  • DROP COLUMN
  • DROP TABLE
  • TRUNCATE TABLE
  • RENAME TABLE

Db2 Constraints

  • Primary Key
  • Foreign Key
  • DEFAULT
  • NOT NULL
  • CHECK
  • UNIQUE

Db2 Data Types

  • Integer
  • Decimal
  • VARCHAR
  • CHAR
  • DATE
  • TIME
  • TIMESTAMP

Useful Functions & Expressions

  • CAST
  • CASE Expression
  • COALESCE

About db2tutorial.com

The db2tutorial.com website provides you with a comprehensive IBM DB2 tutorial with many practical examples and hands-on sessions.

Recent Tutorials

  • Db2 Functions
  • Db2 RANK
  • Db2 ROW_NUMBER
  • Db2 Window Functions
  • What is Db2

Site Links

  • Home
  • About Us
  • Contact Us
  • Privacy Policy
Copyright © © 2021 by www.db2tutorial.com. All Rights Reserved.