Oracle learning: Functions and usage of ASCII and CHR Functions

Source: Internet
Author: User

Oracle provides the following explanations for ASCII and CHR functions:
 
ASCII (x) gets the ASCII value of the character X, CHR () and ASCII () have the opposite effect.
 
That is, the ASCII function is used to convert characters into their corresponding ASCII code, while the CHR function is opposite;
 
Here are some simple examples:
 
Select ascii ('x'), ASCII ('y'), ASCII ('Z') from dual;
 
The statement execution result is 120,121,122 (the ASCII code corresponding to the characters x, y, and z is 120,121,122 ). Then we should easily know the results of select chr ('123'), CHR ('123') from dual.

In the above example, all characters are single characters. What will happen if there are multiple characters? Select ascii ('xy') from dual; the result is 120; select ascii ('x') from dual; the result is 120. We can see from these two examples.
 
"ASCII gives the ascii value of the first character of a string": the ASCII function only takes effect for the first character in your string;
 
Finally, we will introduce several common chr () functions, such as chr (9), chr (10), chr (13), chr (32), chr (34 ), here, chr (9) is a tab, chr (10) is a line break, chr (13) is a carriage return, chr (32) is a space character, and chr (34) is a double quotation mark "".
 
Some people may be confused about the carriage return and line feed, because these two symbols are usually used together. Press enter to return to the beginning of the line, and change the line feed to the next line. Is there a difference between chr (13) and chr (10) in oracle? (There is no difference in the results, because the current language will automatically convert them into "Carriage Return "). That is
 
Declare
 
Begin
 
Dbms_output.put_line ('huiche ');
 
Dbms_output.put_line (chr (10 ));
 
Dbms_output.put_line ('hhh ');
 
End;
 
Same
 
Declare
 
Begin
 
Dbms_output.put_line ('huiche ');
 
Dbms_output.put_line (chr (13 ));
 
Dbms_output.put_line ('hhh ');
 
End;
 
The results of two block outputs are exactly the same.

Related Article

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.