Home > Database > Oracle > body text

How to use translate in oracle

下次还敢
Release: 2024-05-07 13:21:16
Original
633 people have browsed it

The TRANSLATE function in Oracle replaces a character or set of characters in a string. Syntax: TRANSLATE(string, from_list, to_list). Parameters: string (input string), from_list (character or character set to be replaced), to_list (replacement character or character set). Usage: Traverse the characters in from_list, find matches in string and replace them with the corresponding characters in to_list. Examples: Convert lowercase letters to uppercase letters, convert numbers to asterisks, replace specific characters with other characters.

How to use translate in oracle

TRANSLATE function in Oracle

The TRANSLATE function in Oracle is used to convert specific characters or Character set is replaced with another character or character set.

Syntax

<code>TRANSLATE(string, from_list, to_list)</code>
Copy after login

Parameters

  • string: The string to be converted.
  • from_list: List of characters or character sets to be replaced.
  • to_list: Replacement character or character set list, corresponding to the characters in from_list one-to-one.

Usage

The TRANSLATE function works in the following manner:

  1. It iterates over each character or set of characters in from_list.
  2. It looks for each character or set of characters in the string.
  3. If a match is found, it replaces the character or character set in from_list with the corresponding character or character set in to_list.

Example

<code>-- 将字符串中的所有小写字母转换为大写字母
SELECT TRANSLATE('hello world', 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') FROM dual;
-- 结果:HELLO WORLD

-- 将字符串中的数字转换为星号
SELECT TRANSLATE('12345', '0123456789', '**********') FROM dual;
-- 结果:******

-- 将字符串中的特定字符替换为其他字符
SELECT TRANSLATE('Hello, World!', '!,', '??') FROM dual;
-- 结果:Hello?? World??</code>
Copy after login

Notes

  • The lengths of from_list and to_list must be equal.
  • Replacement does not change the original string. It will return a new string.
  • The TRANSLATE function is case-sensitive.
  • If the character or character set to be replaced is not found, no replacement is performed.

The above is the detailed content of How to use translate in oracle. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!