Home > Database > SQL > body text

Function that represents a character in sql

Daniel James Reed
Release: 2024-05-01 23:45:43
Original
503 people have browsed it

The functions that represent a single character in SQL are: SUBSTRING: Extract the substring at the specified position (provides a starting position and a length of 1) CHAR: Creates Unicode characters (accepts Unicode code points) CHR: Creates ASCII characters (Accepts ASCII code points) UNICHAR: Creates Unicode characters (Accepts character names)

Function that represents a character in sql

Functions in SQL that represent a character

There are several functions in SQL that can help obtain or represent a single character:

1. SUBSTRING function

SUBSTRING function extracts the substring at the specified position in the string . To get a single character, provide a starting position and a length of 1.

Syntax: SUBSTRING(string, start_position, length)

Example: Get the first character in the string "Hello":

<code>SELECT SUBSTRING('Hello', 1, 1);
-- 输出:H</code>
Copy after login

2. CHAR function

The CHAR function creates a single character from the Unicode character set. It accepts as argument an integer value that represents the code point of the Unicode character.

Syntax: CHAR(character_code)

Example: Get the Unicode character "A" (code point is 65):

<code>SELECT CHAR(65);
-- 输出:A</code>
Copy after login

3 . CHR function

The CHR function is similar to the CHAR function, but it accepts ASCII character codes as parameters.

Syntax: CHR(character_code)

Example: Get the ASCII character "A" (code point is 65):

<code>SELECT CHR(65);
-- 输出:A</code>
Copy after login

4 . UNICHAR function

The UNICHAR function creates a single character from the Unicode character set. It accepts a string argument that specifies the name of the character to be represented.

Syntax: UNICHAR(character_name)

Example: Get the Unicode character "asterisk" (name is "*):

<code>SELECT UNICHAR('*');
-- 输出:*</code>
Copy after login

The above is the detailed content of Function that represents a character in sql. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Articles by Author
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!