DB2 Tutorial

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

Db2 RIGHT

Db2 RIGHT() function returns a substring that consists of the specified number of rightmost characters from a string.

The following shows the syntax of the RIGHT() function:

LEFT(string, length, unit);

In this syntax:

  • First, specify the source string ( string) from which substring is extracted.
  • Second, specify the number of rightmost characters ( length) to be extracted.
  • Third, optionally specify the unit of the length with the value in the following table.
UnitDescription
 CODEUNITS16Specifies that the length is expressed in terms of 16-bit UTF-16 code units.
 CODEUNITS32Specifies that the length is expressed in terms of 32-bit UTF-32 code units.
 OCTETSSpecifies that the length is expressed in terms of bytes.

This example returns the first three characters of the string 'IBM Db2':

SELECT RIGHT('IBM Db2',3) result FROM sysibm.sysdummy1;

The following shows the output:

RESULT ------- Db2

The following example illustrates how to use the RIGHT() function with a unit:

SELECT RIGHT('Jürgen',5,CODEUNITS16) FROM sysibm.sysdummy1;

This is the output:

RESULT ---------- ürgen

In this tutorial, you have learned how to use the Db2 RIGHT() function to return the number of rightmost characters of a string.

  • Was this tutorial helpful ?
  • YesNo
Previous Db2 LTRIM
Next Db2 RTRIM

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.