天天看点

cast_to_raw oracle,在oracle中使用utl_raw.cast_to_varchar2,将raw转换为varchar…

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

字符集问题 你的PL/SQL DEV的字符集不对

UTL_RAW.CAST_TO_VARCHAR2 converts a raw value into a value of data type VARCHAR2 with the same number of data bytes. The result is treated as if it were composed of single 8-bit bytes, not characters. Multibyte character boundaries are ignored. The data is not modified in any way, it is only changed to data type VARCHAR2.

Syntax result := UTL_RAW.CAST_TO_VARCHAR2(input);

where:

resultis the output value of the function. It is data type VARCHAR2. The value is null if input is null.inputis the input value of datatype RAW to convert to datatype VARCHAR2.

==》正常的例子

问问maclean

SQL> select UTL_RAW.CAST_TO_RAW('问问maclean') from dual;

UTL_RAW.CAST_TO_RAW('问问MACLEAN')--------------------------------------------------------------------------------E997AEE997AE6D61636C65616E

SQL> select utl_raw.cast_to_varchar2('E997AEE997AE6D61636C65616E') as maclean from dual;

MACLEAN--------------------------------------------------------------------------------问问maclean

==》 字符集不对的例子

C:\Users\xiangbli>set nls_lang=american_america.US7ASCII

C:\Users\xiangbli>sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Fri Aug 23 21:32:27 2013

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to:Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit ProductionWith the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> select utl_raw.cast_to_varchar2('E997AEE997AE6D61636C65616E') as maclean from dual;

MACLEAN--------------------------------------------------------------------------------??maclean

==》出现了乱码