1
votes

When using Oracle ascii function:

select ascii('A') from dual;

It return 65 is right.

But,when i using:

select ascii('周') from dual;

The return is 55004.The ascii can represent>255???

How to explain?

Help!!!!

My oracle version:Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production my Characterset:6 NLS_CHARACTERSET ZHS16GBK

2

2 Answers

4
votes

ASCII in the name is a holdover from when Oracle only supported ASCII. It does not mean it only returns ASCII values.

From the docs:

ASCII returns the decimal representation in the database character set of the first character of char.

http://docs.oracle.com/cd/E11882_01/server.112/e41084/functions013.htm#sthref933

So the result depends on the database character set, which can be greater than 255.

1
votes

This may vary with your version of Oracle, but it is probably trying to do you the favor of gracefully handling the non-7bit ASCII value that you are passing (but should not be). The doc in at least one version discusses some handling of non-ASCII inputs (http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions007.htm) though if you are using a different version of oracle you may want to refer to the appropriate docs.

If your docs don't say anything more about how it handles non-7bit characters then the answer is probably not well defined (ie no guarantee from Oracle on behavior) and you may want to consider cleansing your input so you only try calling the ASCII function on values that you know to be in the proper input set.