The length of Chinese Characters in Oralce and the length of oralce Chinese Characters
Generally, we use the String. length () method when verifying the String length at the Java layer. The returned length is the same in both Chinese and English.
However, after a database is inserted, an error is reported (the length exceeds the limit ).
Public class StringLength {public static void main (String [] args) {System. out. println ("test ". length (); System. out. println ("cs ". length ());}}
The console displays the following results:
22
However, in the database, the "digits" of Chinese characters vary according to the character set of the database:
Database Character Set |
Occupied digits |
WE8ISO8859P1 |
1 |
AL32UTF8 |
3 |
ZHS16GBK |
2 |
Therefore, when we set the username field to a maximum of 3, this must be defined in the database.
Varchar (6) in WE8ISO8859P1 case of varchar (3) AL32UTF8 case of varchar (9) ZHS16GBK)
This requires us to consider the application when defining the table.
So how to view the character set of the current database?
select * from nls_database_parameters;
Of course, you should also pay attention to the problem of viewing the character length and byte length in the database, because the varchar type defines the length of bytes.
Varchar (3) is equivalent to varchar (3 byte)
Therefore, the following code appears:
Select length ('test') from dual; -- 2 select lengthb ('test') from dual; -- 4 select length ('cs ') from dual; -- 2 select lengthb ('cs ') from dual; -- 2
Chinese character display in oracle
Add an n prefix, for example, n'chinese '.
Or change the Chinese encoding of the current database.
For more information, see here.
Www.cnblogs.com/..0.html
In pl/SQL, the length of one Chinese Character occupies 3 bytes.
Problem:
This error occurs when the character set used is UTF8!
You can run the following command to View Details:
SQL> select * from v $ nls_parameters where parameter = 'nls _ CHARACTERSET ';
PARAMETER
------------------------------------------------
VALUE
------------------------------------------------
NLS_CHARACTERSET
AL32UTF8
Solution:
We recommend that you use the ZHS16GBK character set!
After this operation, the problem can be solved.
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP MOUNT;
SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;
SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES = 0;
SQL> ALTER DATABASE OPEN;
SQL> ALTER DATABASE CHARACTER SET AL32UTF8/ZHS16GBK;
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP;