日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Oracle Scheduler - NLS_ENV

發(fā)布時間:2023/12/19 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Oracle Scheduler - NLS_ENV 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

What kind of NLS env is used when a scheduler job is running? And what if this job creates some more children jobs?

The answer is that this job and its children will inherit NLS env from the creator's. That means, if you create a scheduler job in an English session, all relative jobs run in English language enviroment. On other hand, if creator runs in non-English languange, so do all jobs.

Some confusing error show up when we use NLS related functions, such as to_char(), to_date() and next_day(). For instance, the next_day() accepts a string type argument and returns the date of next weekday. If we give it the 'Monday' as argument and run it in a non-English session, the error message 'ORA-01846: not a valid day of the week' shows up, because Oracle couldn't recognize 'Monday' as a valid weekday.

Let's test it and have a look. First of all, we are preparing some scripts.

SQL_1:
-- create tales to contain test result
drop table testnls;
create table testnls(dt date, msg varchar2(1000));
truncate table testnls;
select * from testnls;

-- proc uses next_day
create or replace procedure p_testnls1 is
? l_msg varchar2(1000);
begin
? insert into testnls
??? (dt, msg)
? values
??? (sysdate, to_char(next_day(sysdate, 'Monday'),'yyyy-mm-dd'));
? commit;
exception
? when others then
??? l_msg := sqlerrm;
??? rollback;
??? insert into testnls (dt, msg) values (sysdate, l_msg);
??? commit;
end;
/

-- proc uses next_day in subjob
create or replace procedure p_testnls2 is
? l_job int;
begin
? dbms_job.submit(job? => l_job,
????????????????? what => '
? declare???
??? l_msg varchar2(1000);
? begin
? insert into testnls
??? (dt, msg)
? values
??? (sysdate, to_char(next_day(sysdate, ''Monday''),''yyyy-mm-dd''));
??? exception
? when others then
??? l_msg := sqlerrm;
??? rollback;
??? insert into testnls (dt, msg) values (sysdate, l_msg);
??? commit;
? end;?
');
? commit;
end;
/

?

SQL_2: ?re-create the scheduler
begin
? dbms_scheduler.drop_job('TEST_NLS');
end;
/
begin
? -- here uses subjob version process to simulate the WF
? -- that means a running job craetes another subjob to do actual work?
? DBMS_SCHEDULER.CREATE_JOB(job_name??????? => 'TEST_NLS',
??????????????????????????? start_date????? => systimestamp,
??????????????????????????? repeat_interval => 'SYSDATE + 10 / 86400',
??????????????????????????? end_date??????? => null,
??????????????????????????? job_class?????? => 'DEFAULT_JOB_CLASS',
??????????????????????????? job_type??????? => 'PLSQL_BLOCK',
??????????????????????????? job_action????? => 'BEGIN p_testnls2(); END;',
??????????????????????????? comments??????? => 'TEST_NLS');
? DBMS_SCHEDULER.ENABLE(name => 'TEST_NLS');
end;
/

SQL_3: check the scheduler's nls attribute
select j.job_name,
?????? substr(j.nls_env, instr(j.nls_env, 'NLS_DATE_LANGUAGE'), 40)
? from user_scheduler_jobs j
?where j.job_name in ('TEST_NLS');


OK, ?now we do the whole test under Oracle10g
SQL> select * from v$version;?
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE??? 10.2.0.4.0??? Production
TNS for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Productio
NLSRTL Version 10.2.0.4.0 - Production

Step_1
Run SQL_1 to create all necessary objects.

Step_2
Now we are running in an English language session, and we can tell it by this

SQL> select * from nls_session_parameters p where p.parameter='NLS_DATE_LANGUAGE';?
PARAMETER????????????????????? VALUE
------------------------------ ----------------------------------------
NLS_DATE_LANGUAGE????????????? AMERICAN

Step_3
Run SQL_2 to create the scheduler job and check its NLS_ENV attribute by running SQL_3

SQL> @sql_3
JOB_NAME?????????????????????? SUBSTR(J.NLS_ENV,INSTR(J.NLS_E
------------------------------ ----------------------------------------
TEST_NLS?????????????????????? NLS_DATE_LANGUAGE='AMERICAN' NLS_SORT='B

Step_4
So far it work very well.

SQL> select * from testnls;
DT????????? MSG
----------- --------------------------------------------------------------------------------
2008-10-7 2 2008-10-13
2008-10-7 2 2008-10-13
2008-10-7 2 2008-10-13
2008-10-7 2 2008-10-13

Step_5
Let's change nls_date_language to a non_English, and re-run SQL_2,3,4 to check the error message

SQL> alter session set nls_date_language='simplified chinese';?
SQL> select * from nls_session_parameters p where p.parameter='NLS_DATE_LANGUAGE';
PARAMETER????????????????????? VALUE
------------------------------ ----------------------------------------
NLS_DATE_LANGUAGE????????????? SIMPLIFIED CHINESE

SQL> select * from testnls;
?
DT????????? MSG
----------- --------------------------------------------------------------------------------
2008-10-7 2 2008-10-13
2008-10-7 2 2008-10-13
2008-10-7 2 2008-10-13
2008-10-7 2 2008-10-13
2008-10-7 2 ORA-01846: not a valid day of the week
2008-10-7 2 ORA-01846: not a valid day of the week
2008-10-7 2 ORA-01846: not a valid day of the week

轉(zhuǎn)載于:https://www.cnblogs.com/wait4friend/archive/2012/01/30/2334554.html

總結(jié)

以上是生活随笔為你收集整理的Oracle Scheduler - NLS_ENV的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。