Oracle Study之--NLS_DATE_FORMAT
admin
2023-05-10 01:00:49
0

Oracle Study之--NLS_DATE_FORMAT


系统环境:

     操作系统:RedHat EL6

     数据库:    Oracle 11gR2

在RMAN中设置时间格式时,报错:


Oracle Study之--NLS_DATE_FORMAT

Oracle中 NLS_DATE_FORMAT的设置方法 

分类:
Oracle中 NLS_DATE_FORMAT的设置方法
Oracle日期格式默认为:DD-MON-YY,以下是3种方法可以修改使之永久生效;


1、修改glogin.sql文件,这个文件的路径为:
Windows下:
%ORACLE_HOME\sqlplus\admin\
Unix下:
$ORACLE_HOME/sqlplus/admin/
在文件中加入:
alter session set nls_date_format = 'yyyy-mm-dd hh34:mi:ss';


2、修改注册表(windows平台)
开始-->运行-->regedit-->HKEY_LOCAL_MACHINE-->SOFTWARE-->ORACLE-->KEY_ORADb10g_home1
新建字符串值:
NLS_DATE_FORMAT,并设置其值为:YYYY-MM-DD:HH24:MI:SS


3、修改用户环境变量(Unix平台)
export NLS_DATE_FORMAT =AMERICAN
export NLS_DATE_FORMAT ='YYYY-MM-DD HH24:MI:SS'
RMAN会话中设置NLS_DATE_FORMAT 和NLS_LANG
run {
...........
sql 'alter session set NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS";
sql 'alter session set NLS_LANG ="AMERICAN";
...........
}

Oracle 官方解释:


Explanation 

part1:
     NLS_DATE_FORMAT is client centric, not server centric. This way each client can see dates the way he/she needs to. For example clent in Europe is used to dates in DD/MM/YY format while clients in the US are used to MM/DD/YY. Therefore, each client needs to set NLS_DATE_FORMAT on the client box. In Windows, start regedit, go to HKEY_Local_Machine, Software, Oracle and add entry NLS_DATE_FORMAT = 'MM/DD/YYYY'. On Unix set environment variable NLS_DATE_FORMAT.

part2:
part1 is not entirely true.
     NLS_DATE_FORMAT is not that straight forward. And explanation I gave you is not entirely true. There is a lot of articles in Oracle's MetaLink on that topic. If you are MetaLink customer check http://support.oracle.com.sg/met ... OT&p_id=74375.1

     NLS_DATE_FORMAT is used if a date format mask is not specified in application code. The effective NLS_DATE_FORMAT is determined by the following (in order of precedence): 

1. Session NLS_DATE_FORMAT (via ALTER SESSION command) 
2. Client side NLS_DATE_FORMAT (from client environment variables/registry settings) 
3. Instance NLS_DATE_FORMAT (from init.ora file) 
4. Database NLS_DATE_FORMAT 


     Session NLS_DATE_FORMAT is set to client side NLS_DATE_FORMAT (explicit or implicit) ONLY if NLS_LANG is set. Another words, if NLS_LANG is set, then session NLS_DATE_FORMAT will be taken from the client. If clent NLS_LANG is set and client NLS_DATE_FORMAT is not, session NLS_DATE_FORMAT will default to DD-MON-YY (and that was exactly what you experienced). If NLS_LANG is not specified on the client side, NLS_DATE_FORMAT will be taken from instance NLS_DATE_FORMAT which is NLS_DATE_FORMAT from INIT.ORA. If NLS_DATE_FORMAT is not set in INIT.ORA, session NLS_DATE_FORMAT will default to DD-MON-YY.


相关内容

热门资讯

以军士兵集体丢掉武器抗命,大喊... 据凤凰卫视报道,以色列国防军一军事基地7月30日发生士兵抗命事件,约120名士兵抗议指挥官做法,将武...
蒋成华任商务部副部长 国务院任免国家工作人员。任命蒋成华为商务部副部长。免去蒋成华的商务部国际贸易谈判副代表职务。
伊朗驻华大使:在军事威胁下,不... 新华社北京7月31日电(记者刁慧琳) 伊朗驻华大使法兹里7月28日表示,伊美回到谈判桌的前提是美国必...
伊朗革命卫队在霍尔木兹海峡击中... 当地时间31日,伊朗伊斯兰革命卫队发布声明称,革命卫队海军当天在霍尔木兹海峡击中并扣留了两艘违反禁令...
美媒:特朗普,遇到了一个更强硬... 据《纽约时报》7月29日报道,就在特朗普总统看似放弃战事升级计划几天后,美国再次与伊朗交火。上周末,...
女子做气管镜时不幸身亡,丈夫称... 7月29日,西安刘先生反映妻子在当地医院做支气管镜检查时死亡,看监控时发现医生疑有违规操作。刘先生表...
全网“帮卖西瓜”,然后呢? 近日,河南部分地区西瓜滞销的消息在网上热度很高。很多地方也伸出援手:有景区收购千斤西瓜、免费赠予游客...
美媒:乌克兰袭击伊朗船只,险引... 据《纽约时报》7月28日报道,据伊朗和西方官员称,伊朗曾考虑攻击乌克兰的一个港口,以报复乌克兰对一艘...
20年里,他只画美女,用东方风... 迈进KIM在上海的工作室,迎面是一整墙的美女们。她们像是刚从一场时髦的沙龙里退场,或倚或立,眉宇间是...
Google在港推出AI代理G... 观点网讯:7月29日,Google在香港推出AI代理Gemini Spark,该代理可全天候在后台运...