将NVARCHAR2转换为VARCHAR2:
- declare
- v_username varchar2(12) ;
- v_nm_login nvarchar2(12);
- begin
- select utl_raw.cast_to_varchar2(utl_raw.cast_to_raw(v_nm_login))
- into v_username
- from dual;
- end;
将VARCHAR2转换为NVARCHAR2:
- declare
- v_username varchar2(12) := 'pavan408';
- v_nm_login nvarchar2(12);
- begin
- select utl_raw.cast_to_nvarchar2(utl_raw.cast_to_raw(v_username))
- into v_nm_login
- from dual;
- end;
补充,以上转换如果含有汉字有可能转换失败,都成了“??”,可以用Translate函数来转换
例如
- Translate('你好' USING NCHAR_CS)--此处的“你好”是varchar类型
- Translate(yourWords USING CHAR_CS)--此处的yourWords是nvarchar类型