-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
string-functions: add instructions for using ASCII() and BIN() #15481
Merged
ti-chi-bot
merged 17 commits into
pingcap:master
from
qiancai:provide-instructions-for-ASCII(str)
Jan 5, 2024
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2dda40e
Update string-functions.md
qiancai d5f0e8a
Update string-functions.md
qiancai 2754045
Update string-functions.md
qiancai 7348dd2
Update string-functions.md
qiancai 89e7d35
Update string-functions.md
qiancai fce42c2
Update string-functions.md
qiancai 6442f9f
Update functions-and-operators/string-functions.md
qiancai 4698d02
Update string-functions.md
qiancai 776bff1
Apply suggestions from code review
qiancai bc9eb90
Update string-functions.md
qiancai 6338f66
Update string-functions.md
qiancai 45fcfa0
Update string-functions.md
qiancai 11425a4
Apply suggestions from code review
qiancai 81b8236
Update functions-and-operators/string-functions.md
qiancai a90d322
Update punctuation
lilin90 e48d6a7
Update punctuation
lilin90 2df6fc3
Update format
lilin90 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,11 +13,90 @@ TiDB 支持使用大部分 MySQL 5.7 中提供的[字符串函数](https://dev.m | |
|
||
### [`ASCII()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_ascii) | ||
|
||
返回最左字符的数值 | ||
`ASCII()` 函数用于获取输入的参数中最左字符的 ASCII 值。该参数可以为字符串或数字。 | ||
|
||
- 如果输入参数不为空,该函数返回参数中最左字符的 ASCII 值。 | ||
- 如果输入参数为空,该函数返回 `0`。 | ||
- 如果输入参数为 `NULL`,该函数返回 `NULL`。 | ||
|
||
> **注意:** | ||
> | ||
> `ASCII()` 只能处理那些用 8 个二进制数字(即单个字节)来表示的字符。 | ||
|
||
示例: | ||
|
||
```sql | ||
SELECT ASCII('A'); | ||
|
||
+------------+ | ||
| ASCII('A') | | ||
+------------+ | ||
| 65 | | ||
+------------+ | ||
``` | ||
|
||
```sql | ||
SELECT ASCII('TiDB'); | ||
|
||
+---------------+ | ||
| ASCII('TiDB') | | ||
+---------------+ | ||
| 84 | | ||
+---------------+ | ||
``` | ||
|
||
```sql | ||
SELECT ASCII(23); | ||
|
||
+-----------+ | ||
| ASCII(23) | | ||
+-----------+ | ||
| 50 | | ||
+-----------+ | ||
``` | ||
|
||
### [`BIN()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_bin) | ||
|
||
返回一个数的二进制值的字符串表示 | ||
`BIN()` 函数用于将输入的参数转换为其二进制值的字符串表示形式。该参数可以为字符串或数字。 | ||
|
||
- 如果输入参数为正数,该函数返回该参数的二进制值的字符串表示形式。 | ||
- 如果输入参数为负数,该函数会将该参数的绝对值转换为其二进制值,然后对二进制值的每位取反(`0` 变为 `1`,`1` 变为 `0`),最后加上 `1`。 | ||
- 如果输入参数为字符串,且该字符串中只包含数字,该函数将按照该数字返回结果。例如,`"123"` 与 `123` 的返回结果相同。 | ||
- 如果输入参数为字符串,且该字符串第一个字符不是数字(如 `"q123"`),该函数返回 `0`。 | ||
- 如果输入参数为字符串,且该字符串由数字和非数字组成,该函数将按照该参数中最前面连续的数字返回结果。例如,`“123q123”` 与 `123` 的返回结果相同。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
这是中文引号,需要更新一下 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
- 如果输入参数为 `NULL`,该函数返回 `NULL`。 | ||
|
||
示例: | ||
|
||
```sql | ||
SELECT BIN(123); | ||
|
||
+----------+ | ||
| BIN(123) | | ||
+----------+ | ||
| 1111011 | | ||
+----------+ | ||
``` | ||
|
||
```sql | ||
SELECT BIN(-7); | ||
|
||
+------------------------------------------------------------------+ | ||
| BIN(-7) | | ||
+------------------------------------------------------------------+ | ||
| 1111111111111111111111111111111111111111111111111111111111111001 | | ||
+------------------------------------------------------------------+ | ||
``` | ||
|
||
```sql | ||
SELECT BIN("123q123"); | ||
|
||
+----------------+ | ||
| BIN("123q123") | | ||
+----------------+ | ||
| 1111011 | | ||
+----------------+ | ||
``` | ||
|
||
### [`BIT_LENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_bit-length) | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的空,其实是指空字符串。