-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : Dialects MySQL string fuction (#162)
* added : git ignore * Added String fuction * Review Correction and Debug by inspecting UI one by one
- Loading branch information
1 parent
0e3e6dc
commit cf26feb
Showing
45 changed files
with
723 additions
and
15 deletions.
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 |
---|---|---|
|
@@ -33,3 +33,4 @@ configs.json | |
query-master-data/ | ||
|
||
.env | ||
yarn.lock |
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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
ASCII(str) | ||
|
||
Returns the numeric value of the leftmost character of the string str. Returns 0 if str is the empty string. Returns NULL if str is NULL ASCII() works for 8-bit characters. | ||
|
||
``` | ||
SELECT ASCII('2'); | ||
-> 50 | ||
SELECT ASCII(2); | ||
-> 50 | ||
SELECT ASCII('dx'); | ||
-> 100 | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
BIN(N) | ||
|
||
Returns a string representation of the binary value of `N`, where `N` is a longlong (BIGINT) number. This is equivalent to CONV(N,10,2) Returns `NULL` if `N` is `NULL`. | ||
|
||
``` | ||
SELECT BIN(12); | ||
-> '1100' | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
BIT_LENGTH(str) | ||
|
||
Returns the length of the string str in bits. Returns NULL if str is NULL. | ||
|
||
``` | ||
SELECT BIT_LENGTH('text'); | ||
-> 32 | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
CHAR(N,...[USING charset_name]) | ||
|
||
<!-- Though build:dialect it not working --> | ||
|
||
CHAR() interprets each argument N as an integer and returns a string consisting of the characters given by the code values of those integers. NULL values are skipped. | ||
|
||
``` | ||
mysql> SELECT CHAR(77,121,83,81,'76'); | ||
+--------------------------------------------------+ | ||
| CHAR(77,121,83,81,'76') | | ||
+--------------------------------------------------+ | ||
| 0x4D7953514C | | ||
+--------------------------------------------------+ | ||
1 row in set (0.00 sec) | ||
mysql> SELECT CHAR(77,77.3,'77.3'); | ||
+--------------------------------------------+ | ||
| CHAR(77,77.3,'77.3') | | ||
+--------------------------------------------+ | ||
| 0x4D4D4D | | ||
+--------------------------------------------+ | ||
1 row in set (0.00 sec) | ||
``` | ||
|
||
By default, CHAR() returns a binary string. To produce a string in a given character set, use the optional USING clause: | ||
|
||
``` | ||
mysql> SELECT CHAR(77,121,83,81,'76' USING utf8mb4); | ||
+---------------------------------------+ | ||
| CHAR(77,121,83,81,'76' USING utf8mb4) | | ||
+---------------------------------------+ | ||
| MySQL | | ||
+---------------------------------------+ | ||
1 row in set (0.00 sec) | ||
mysql> SELECT CHAR(77,77.3,'77.3' USING utf8mb4); | ||
+------------------------------------+ | ||
| CHAR(77,77.3,'77.3' USING utf8mb4) | | ||
+------------------------------------+ | ||
| MMM | | ||
+------------------------------------+ | ||
1 row in set, 1 warning (0.00 sec) | ||
mysql> SHOW WARNINGS; | ||
+---------+------+-------------------------------------------+ | ||
| Level | Code | Message | | ||
+---------+------+-------------------------------------------+ | ||
| Warning | 1292 | Truncated incorrect INTEGER value: '77.3' | | ||
+---------+------+-------------------------------------------+ | ||
1 row in set (0.00 sec) | ||
``` | ||
|
||
If USING is given and the result string is illegal for the given character set, a warning is issued. Also, if strict SQL mode is enabled, the result from CHAR() becomes NULL. | ||
|
||
If CHAR() is invoked from within the mysql client, binary strings display using hexadecimal notation, depending on the value of the --binary-as-hex. For more information about that option, see Section 4.5.1, “mysql — The MySQL Command-Line Client”. | ||
|
||
CHAR() arguments larger than 255 are converted into multiple result bytes. For example, CHAR(256) is equivalent to CHAR(1,0), and CHAR(256*256) is equivalent to CHAR(1,0,0): | ||
|
||
``` | ||
mysql> SELECT HEX(CHAR(1,0)), HEX(CHAR(256)); | ||
+----------------+----------------+ | ||
| HEX(CHAR(1,0)) | HEX(CHAR(256)) | | ||
+----------------+----------------+ | ||
| 0100 | 0100 | | ||
+----------------+----------------+ | ||
1 row in set (0.00 sec) | ||
mysql> SELECT HEX(CHAR(1,0,0)), HEX(CHAR(256*256)); | ||
+------------------+--------------------+ | ||
| HEX(CHAR(1,0,0)) | HEX(CHAR(256*256)) | | ||
+------------------+--------------------+ | ||
| 010000 | 010000 | | ||
+------------------+--------------------+ | ||
1 row in set (0.00 sec) | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CHAR_LENGTH(str) | ||
|
||
Returns the length of the string str, measured in code points. A | ||
multibyte character counts as a single code point. This means | ||
that, for a string containing two 3-byte characters, | ||
LENGTH() returns 6, whereas CHAR_LENGTH() returns 2, as shown here: | ||
|
||
``` | ||
mysql> SET @dolphin:='海豚'; | ||
Query OK, 0 rows affected (0.01 sec) | ||
mysql> SELECT LENGTH(@dolphin), CHAR_LENGTH(@dolphin); | ||
+------------------+-----------------------+ | ||
| LENGTH(@dolphin) | CHAR_LENGTH(@dolphin) | | ||
+------------------+-----------------------+ | ||
| 6 | 2 | | ||
+------------------+-----------------------+ | ||
1 row in set (0.00 sec) | ||
``` | ||
|
||
CHAR_LENGTH() returns NULL if str is NULL. | ||
|
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CHARACTER_LENGTH(str) | ||
|
||
CHARACTER_LENGTH() is a synonym for CHAR_LENGTH(). |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
CONCAT(str1,str2,...) | ||
|
||
Returns the string that results from concatenating the arguments. May have one or more arguments. If all arguments are nonbinary strings, the result is a nonbinary string. If the arguments include any binary strings, the result is a binary string. A numeric argument is converted to its equivalent nonbinary string form. | ||
|
||
CONCAT() returns NULL if any argument is NULL. | ||
|
||
``` | ||
mysql> SELECT CONCAT('My', 'S', 'QL'); | ||
-> 'MySQL' | ||
mysql> SELECT CONCAT('My', NULL, 'QL'); | ||
-> NULL | ||
mysql> SELECT CONCAT(14.3); | ||
-> '14.3', mysql> SELECT 'My' 'S' 'QL'; | ||
-> 'MySQL' | ||
``` | ||
|
||
For quoted strings, concatenation can be performed by placing the strings next to each other: | ||
|
||
``` | ||
mysql> SELECT 'My' 'S' 'QL'; | ||
-> 'MySQL' | ||
``` | ||
|
||
If CONCAT() is invoked from within the mysql client, binary string results display using hexadecimal notation, depending on the value of the --binary-as-hex. For more information about that option, see Section 4.5.1, [mysql — The MySQL Command-Line Client](https://dev.mysql.com/doc/refman/8.0/en/mysql.html). |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CONCAT_WS(separator,str1,str2,...) | ||
|
||
CONCAT_WS() stands for Concatenate With Separator and is a special form of CONCAT(). The first argument is the separator for the rest of the arguments. The separator is added between the strings to be concatenated. The separator can be a string, as can the rest of the arguments. If the separator is NULL, the result is NULL. | ||
|
||
``` | ||
mysql> SELECT CONCAT_WS(',','First name','Second name','Last Name'); | ||
-> 'First name,Second name,Last Name' | ||
mysql> SELECT CONCAT_WS(',','First name',NULL,'Last Name'); | ||
-> 'First name,Last Name' | ||
``` | ||
|
||
CONCAT_WS() does not skip empty strings. However, it does skip any NULL values after the separator argument. | ||
|
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
ELT(N,str1,str2,str3,...) | ||
|
||
ELT() returns the Nth element of the list of strings: str1 if N = 1, str2 if N = 2, and so on. Returns NULL if N is less than 1, greater than the number of arguments, or NULL. ELT() is the complement of FIELD(). | ||
|
||
``` | ||
mysql> SELECT ELT(1, 'Aa', 'Bb', 'Cc', 'Dd'); | ||
-> 'Aa' | ||
mysql> SELECT ELT(4, 'Aa', 'Bb', 'Cc', 'Dd'); | ||
-> 'Dd' | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
EXPORT_SET(bits,on,off[,separator[,number_of_bits]]) | ||
|
||
Returns a string such that for every bit set in the value bits, you get an on string and for every bit not set in the value, you get an off string. Bits in bits are examined from right to left (from low-order to high-order bits). Strings are added to the result from left to right, separated by the separator string (the default being the comma character ,). The number of bits examined is given by number_of_bits, which has a default of 64 if not specified. number_of_bits is silently clipped to 64 if larger than 64. It is treated as an unsigned integer, so a value of −1 is effectively the same as 64. | ||
|
||
``` | ||
mysql> SELECT EXPORT_SET(5,'Y','N',',',4); | ||
-> 'Y,N,Y,N' | ||
mysql> SELECT EXPORT_SET(6,'1','0',',',10); | ||
-> '0,1,1,0,0,0,0,0,0,0' | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FIELD(str,str1,str2,str3,...) | ||
|
||
Returns the index (position) of str in the str1, str2, str3, ... list. Returns 0 if str is not found. ,If all arguments to FIELD() are strings, all arguments are compared as strings. If all arguments are numbers, they are compared as numbers. Otherwise, the arguments are compared as double. | ||
|
||
``` | ||
mysql> SELECT FIELD('Bb', 'Aa', 'Bb', 'Cc', 'Dd', 'Ff'); | ||
-> 2 | ||
mysql> SELECT FIELD('Gg', 'Aa', 'Bb', 'Cc', 'Dd', 'Ff'); | ||
-> 0 | ||
``` | ||
|
||
If str is NULL, the return value is 0 because NULL fails equality comparison with any value. FIELD() is the complement of ELT(). | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FIND_IN_SET(str,strlist) | ||
|
||
Returns a value in the range of 1 to N if the string str is in the string list `strlist` consisting of N substrings. A string list is a string composed of substrings separated by characters. If the first argument is a constant string and the second is a column of type SET, the FIND_IN_SET() function is optimized to use bit arithmetic. Returns 0 if str is not in `strlist` or if `strlist` is the empty string. Returns NULL if either argument is NULL. This function does not work properly if the first argument contains a comma (,) character. | ||
|
||
``` | ||
mysql> SELECT FIND_IN_SET('b','a,b,c,d'); | ||
-> 2 | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM_BASE64(str) | ||
|
||
Takes a string encoded with the base-64 encoded rules used by TO_BASE64() and returns the decoded result as a binary string. The result is NULL if the argument is NULL or not a valid base-64 string. See the description of TO_BASE64() for details about the encoding and decoding rules. | ||
|
||
``` | ||
mysql> SELECT TO_BASE64('abc'), FROM_BASE64(TO_BASE64('abc')); | ||
-> 'JWJj', 'abc' | ||
``` | ||
|
||
If FROM_BASE64() is invoked from within the mysql client, binary strings display using hexadecimal notation. You can disable this behavior by setting the value of the --binary-as-hex to 0 when starting the mysql client. For more information about that option, see Section 4.5.1, “mysql — The MySQL Command-Line Client”. |
Oops, something went wrong.