本文介绍 nls_date_format。
适用版本
OceanBase 数据库所有版本
nls_date_format
nls_date_format 是 oracle 模式下的系统变量,用于控制 date 类型转 str 的格式,以及 str 隐式转 date 的格式。
| 属性 | 描述 |
|---|---|
| 参数类型 | varchar |
| 默认值 | DD-MON-RR |
| 取值范围 | NULL |
| 生效范围 |
|
| 是否参与序列化 | 是 |
查询表为分区表,分区列为 date 类型。例如:create table t(c1 date) partition by hash(c1) partitions 8;。
查询语句 select * from t where c1= '20-DEC-21'; 如果不指定 nls_date_format 变量,ODP 会使用默认 DD-MON-RR 格式来转换 c1= 为 date 类型,如果使用非 DD-MON-RR 格式,需要修改 nls_date_format 相关变量,ODP 需要正确将字符串转换为 date 类类型才能正确路由。
常见问题
远程路由
例:
- DDL:
create table t(c1 date) partition by hash(c1) partitions 8; - DML:
select * from t where c1= '2022-12-12';
ODP 无法正确路由,ODP 使用默认转换格式 DD-MON-RR,无法正确转换 '2022-12-12'。
**解决:**设置 nls_date_format 为所指定的日期字符串的格式:
obclient> alter session set nls_date_format='yyyy-mm-dd';