For the use of ASCII and CHR functions, Oracle gives the following explanations:
ASCII (x) Gets the ASCII value of the character X, CHR () and ASCII () with the opposite effect.
That is: The ASCII function is used to convert the character to its corresponding ASCII code, while the CHR function is the opposite;
Let me look at some simple examples:
SELECT ASCII (' x '), ASCII (' Y '), ASCII (' Z ') from dual;
The result of the statement execution is 120,121,122 (that is, the ASCII code corresponding to the character x, Y, 120,121,122 respectively). Then select Chr (' 121 '), Chr (' 122 ') from dual, the result of which we should be very easy to know.
All of our examples above are single characters, so what happens if you have multiple characters? SELECT ASCII (' XY ') from dual; The result is 120;select ASCII (' x ') from dual; The result is 120. From these two examples we may have seen something.
"ASCII gives the ASCII value of the first character of a string" that is: the ASCII function only works on the only character in the string you give;
Finally, we introduce several commonly used CHR () functions, Chr (9), CHR, Chr (+), Chr (34), where CHR (9) is TAB,CHR (10) is a newline character, Chr (13) is a carriage return, Chr (32) is a character line, Chr (34) is a double quote "" ".
There may be some confusion about carriage return and line breaks, because the two symbols are used together. Returns to the beginning of the line, and wraps to the next line. Can we use CHR (13) and Chr (10) in Oracle to make a difference? (The result is no different, because the language now automatically turns them into "carriage return"). That
Declare
Begin
Dbms_output.put_line (' Huiche ');
Dbms_output.put_line (Chr (10));
Dbms_output.put_line (' hhh ');
End
With
Declare
Begin
Dbms_output.put_line (' Huiche ');
Dbms_output.put_line (Chr (13));
Dbms_output.put_line (' hhh ');
End
The result of the two block output is exactly the same.
Oracle Learning: The role and usage of ASCII,CHR functions