Converts strings between character sets.
CSCONVERT( string-expression, target-charset-string [, source-charset-string [, options ] ] )
string-expression The string to be converted.
target-charset-string The destination character set. target-charset-string can be any of the SQL Anywhere supported character set labels. It can also be:
os_charset Specify this to use the character set used by the operating system that is hosting the database server.
char_charset Specify this to use the CHAR character set used by the database.
nchar_charset Specify this to use the NCHAR character set used by the database.
options You can specify one of the following options:
Read or write a byte order mark (BOM) Specify read_bom=on or read_bom=off to turn on or off reading byte order marks. Specify write_bom=on or write_bom=off to turn on or off writing byte order marks. By default, the behavior is read_bom=on and write_bom=off.
source-charset-string The character set used for string-expression. The default is db_charset (the database character set). source-charset-string can be any of the SQL Anywhere supported character set labels. It can also be:
os_charset Specify this to use the character set used by the operating system that is hosting the database server.
char_charset Specify this to use the CHAR character set used by the database.
nchar_charset Specify this to use the NCHAR character set used by the database.
LONG BINARY
You can view the list of character sets supported by SQL Anywhere by running the following command:
dbinit -le |
For more information about the character set labels you can use with this function, see Supported character sets.
SQL/2008 Vendor extension. In the SQL/2008 standard, conversion of string data from one charset to another is accomplished with the CONVERT function (not to be confused with the SQL Anywhere CONVERT function) which has different arguments than CSCONVERT.
This fragment converts the mytext column from the Traditional Chinese character set to the Simplified Chinese character set:
SELECT CSCONVERT( mytext, 'cp936', 'cp950' ) FROM mytable; |
This fragment converts the mytext column from the database character set to the Simplified Chinese character set:
SELECT CSCONVERT( mytext, 'cp936' ) FROM mytable; |
If a file name is stored in the database, it is stored in the database character set. If the server will read from or write to a file whose name is stored in a database (for example, in an external stored procedure), the file name must be explicitly converted to the operating system character set before the file can be accessed. File names stored in the database and retrieved by the client are converted automatically to the client character set, so explicit conversion is not necessary.
This fragment converts the value in the filename column from the database character set to the operating system character set:
SELECT CSCONVERT( filename, 'os_charset' ) FROM mytable; |
A table contains a list of file names. An external stored procedure takes a file name from this table as a parameter and reads information directly out of that file. The following statement works when character set conversion is not required:
SELECT MYFUNC( filename ) FROM mytable; |
The mytable clause indicates a table with a filename column. However, if you need to convert the file name to the character set of the operating system, you would use the following statement.
SELECT MYFUNC( csconvert( filename, 'os_charset' ) ) FROM mytable; |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |