Oracle nvarchar2 错误解决方案
问题:
使用 substr函数截取指定字符串时,取出4位字符 年(例如2019),结果只取出3位(例如201);
问题原因:
字符类型 nvarchar2
解决方案:
通过 TRANSLATE函数将 nvarchar2 转换成 varchar2 。
问题重现:
---1 创建测试数据
create table t1(id number,t_format nvarchar2(100),t_name varchar2(100));
insert into t1 values(1,'abcde2019xxx0707uuu','abcde2019xxx0707uuu');
commit;
---2 通过substr函数截取年月日
select id,
t_format,
t_name,
length(t_format),
length(t_name),
substr(t_format, 6, 4),
substr(t_format, 13, 4),
substr(t_name, 6, 4),
substr(t_name, 13, 4)
from t1;
select id,
t_format,
t_name,
substr(t_format, 6, 5),
substr(t_format, 13, 5),
substr(t_name, 6, 4),
substr(t_name, 13, 4)
from t1;
---3 通过 TRANSLATE函数将 nvarchar2 转换成 varchar2
select id,
t_format,
t_name,
substr(utl_raw.cast_to_varchar2(utl_raw.cast_to_raw(Translate(t_format USING CHAR_CS))),6,4),
substr(utl_raw.cast_to_varchar2(utl_raw.cast_to_raw(Translate(t_format USING CHAR_CS))),13,4),
substr(t_name, 6, 4),
substr(t_name, 13, 4)
from t1;
https://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements001.htm#SQLRF30020
NVARCHAR2 Data Type
The NVARCHAR2 data type is a Unicode-only data type. When you create a table with an NVARCHAR2 column, you supply the maximum number of characters it can hold. Oracle subsequently stores each value in the column exactly as you specify it, provided the value does not exceed the maximum length of the column.
The maximum length of the column is determined by the national character set definition. Width specifications of character data type NVARCHAR2 refer to the number of characters. The maximum column size allowed is 4000 bytes.
更多Oracle相关信息见Oracle 专题页面 https://www.linuxidc.com/topicnews.aspx?tid=12
- oracle通过oerr快速找到相应错误代码的概述及解决方案
- Oracle 数据库基础 出现invalid username/password; logon denied错误解决方案
- oracle逻辑备份失败报JOB无法执行的错误,解决方案
- 启动oracle10监听器错误:本地计算机上的OracleOraDb10g_home1TNSListener服务启动后又停止了解决方案
- oracle EBS 报表outofmemory错误及解决方案(压缩下载)
- Oracle新手最经常碰到的6个错误及解决方案(监听器的错误)
- Oracle 10g "RemoteOperationException: ERROR: Wrong password for user"错误 解决方案
- 安装oracle 12c [INS-30131] 错误解决方案
- 手工创建Oracle遇到的几个错误及解决方案
- Oracle中常出现的错误信息及解决方案
- oracle ORA-39064: 无法写入日志文件 ORA-29285: 文件写入错误(解决方案)
- Oracle ORA-01034&ORA-03113错误解决方案
- 启动oracle11监听器错误:本地计算机上的OracleOraDb11g_home1TNSListener服务启动后又停止了解决方案又一方法
- 远程连接Oracle报ORA-12545错误解决方案
- 天易04----oracle数据库出现oracle initialization or shutdown in progress 错误的解决方案
- Oracle常见错误问题收集和解决方案
- 使用sqoop1.4.4从oracle导入数据到hive中错误记录及解决方案
- Oracle错误代码案例总结及解决方案
- oracle新手最常碰到的6个错误及解决方案
- 连接 Oracle 协议适配器错误 的解决方案