Oracle Learning: The role and usage of ASCII,CHR functions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.