ã¯ããã«
ãã®èšäºã§ã¯ãOracleã®æ¥ä»åœ¢åŒãšãã®åŠçã®ããã€ãã®æ©èœã«ã€ããŠèª¬æããŸãã ãã®èšäºã§ã¯ãããã€ãã®æšæºçãªæ¥ä»æžåŒãã¹ã¯ãæååããæ¥ä»ãžã®æ瀺çããã³æé»çãªå€æãããã³ãã®ããã»ã¹ã«åœ±é¿ããè¿œå ã®ãã©ã¡ãŒã¿ãŒã®æŠèŠã説æããŸãã èšäºã®æåã®éšåãšåæ§ã«ããã®è³æã®èª¬æã¯ãéæšæºã®ãã©ãŒãããæ©èœã瀺ãäŸã«åºã¥ããŠããŸãã æé»çãªå€æããã»ã¹ã«é¢ä¿ããOracleã¡ã«ããºã ã«ã€ããŠè©³ãã調ã¹ãŸãã ã»ãšãã©ã®æ©èœã¯ãããã¥ã¡ã³ãã®é¢é£ã»ã¯ã·ã§ã³ãžã®ãªã³ã¯ã§èª¬æãããŠããŸãã
æåã¯ãæ¥ä»ã«é¢ããèšäºãæžãã€ããã¯ãããŸããã§ãããããã®ãããã¯ã«é¢ãã1ã€ã®åé¡ã ããæ€èšããããšã«å°å¿µããã€ããã§ããã ãã ããäœæ¥äžã«Oracleã®ããŸããŸãªè¿œå æ©èœãã«ããŒããå¿ èŠããããæ°ããäŸãç»å Žãå§ããŸããã ãã®ããã1ã€ã®åé¡ã®æ€èšãå°ããªèšäºã«ãªããŸããã æãèå³æ·±ããããã¯ã§ã¯ãªãã«ãããããããéå±ãªãã®ã«ãªã£ãããšãé¡ã£ãŠããŸãã
æŒç®åã«ããé åºã®æ©èœãnot inã®æäœãããã³æé»çãªåå€æã®äŸã«é¢ããèšäºã®æåã®éšåã¯ãã¡ãã§ãã
To_dateé¢æ°ãšæ¥ä»åœ¢åŒ
ãããã¯ã®æžåŒèšå®ã奜ããªããã°ã©ããŒã¯ã»ãšãã©ããŸããã ããšãã°ãäžéšã®ã³ãŒã¹ã§ã¯ãæ¥ä»ã®æžåŒèšå®ãšå°åæšæºã®ãããã¯ã¯ãç¹ã«ãã¬ãŒãã³ã°ã®æçµæ¥ã®æåŸã®æéã«é 眮ãããŸãã ãªã¹ããŒã¯éå±ã§ãã ãã®çç±ã¯ãæšæºã¿ã¹ã¯ã§æ¯èŒçãŸãã«äœ¿çšãããå€æ°ã®æ¢åã®ãã©ãŒãããã§ãã ã»ãšãã©ã®å Žåããã¹ã¯ã¯to_number ã to_char ãããã³to_dateã® 3ã€ã®é¢æ°ã§äœ¿çšãããŸãã 3ã€ã®å Žåãã¹ãŠã§ããã¹ã¯ã¯2çªç®ã®ãªãã·ã§ã³ã®ãã©ã¡ãŒã¿ãŒã§ãã ãããŠã æ°å€ããã©ãŒãããããããã®æ£æ°ã®ãã¹ã¯ãå€ããå°ãªããããå Žå ã æ¥ä»ããããã€ã«ãã©ãŒãããããããã®ãã¹ã¯ã«å ããŠã ãµãã£ãã¯ã¹ãšä¿®é£ŸåããããŸãã
ãã¡ãããå€æ°ã®ãã¹ã¯ã䜿çšã§ããããšã¯è¯å®çãªããšã§ããããšãã°ãããã°ã©ããŒã®æ¥ã2011幎9æ13æ¥ã§ãããã©ããã確èªããããã«ã幎ã®æ¥æ°ãè¿ããã¹ã¯ãDDDãã䜿çšã§ããŸãã
-- â1 select to_char(to_date('13.09.2011'),'DDD') "Programmers day" from dual;
æžåŒèšå®ã®æãããªå©ç¹ã«ããããããããã®èšäºã®2çªç®ã®ããŒãã§ã¯ãæ¥ä»æžåŒã®æŠèŠãšãšããŸããã¯ãªãã¹ã¯ã®äœ¿çšäŸãå«ããã€ããã¯ãããŸããã§ããã 第äžã«ã誰ããèå³ãæã€ããšã¯ãŸããããŸããã第äºã«ãèè ã¯è€éãªãã©ãŒãããã®å€§ãã¡ã³ã§ã¯ãããŸããã ãã®ã»ã¯ã·ã§ã³ã衚瀺ãããå¯äžã®çç±ã¯ãRR圢åŒã®äœ¿çšã«é¢ããèªè ããã®è³ªåã§ãã
ã»ã¯ã·ã§ã³ã®ã¡ã€ã³ãããã¯ã«çŽæ¥ç§»åããåã«ãæ¥ä»ã®æäœã®éæšæºçãªäŸãããã€ãèŠãŠã¿ãŸãããã
äŸ1 åãæšãŠããããã¿ãŒã³ã䜿çšãã
æšæºã®ãã©ãŒãããããå§ããŸãããã ä»æ¥ã®æ¥ä»ã¯2011幎9æ16æ¥ã§ããã次ã®ãªã¯ãšã¹ãã¯æºããããŸããïŒ
-- â2 select to_char(sysdate, 'YYYY') from dual; -- â3 select to_date('03', 'DD') from dual;
ãªã¯ãšã¹ãçªå·2ã¯ãæ¥ä»ãæååã«å€æããåžæãã圢åŒã«å€æããå žåçãªäŸã§ãã å¯äžã®éãã¯ããDD.MM.YYããŸãã¯ãDD-MON-YYYYãã¿ã€ãã®ããäžè¬çãªãã¹ã¯ã®ä»£ããã«ã幎ã®ã¿ãèšå®ãããã¹ã¯ã䜿çšããããšã§ãã ãªã¯ãšã¹ãçªå·2ã¯æ£åžžã«å®è¡ãããçŸåšã®å¹Žã4æ¡ã®åœ¢åŒã§è¿ãããŸãã ã2011ãã
ã¯ãšãª3ã¯ããå°ããããããã§ããããã¯ãæååãåãæšãŠãããæžåŒãã¹ã¯ã䜿çšããæ¥ä»ãžã®æ瀺çãªå€æã®å žåçãªäŸã§ãããããã£ãŠãæ§æã®èŠ³ç¹ãããã¯ãšãªã¯æ£ãããæ£åžžã«å®è¡ãããŸãã ããéèŠãªåé¡ã¯ããã®å®è£ ã®çµæã§ãã 1æ¥ããäžããããªãå Žåã圌ã¯äœæ¥ç®ãè¿ããŸããïŒ ãã®è³ªåã«çããåã«ãæ瀺çã«èšå®ãããŠããªãå Žåã«Oracleãã©ã®ããã«æéãèšå®ãããæãåºããŠã¿ãŸãããã
-- â4 select to_char(to_date('03.02.2011','DD.MM.YYYY'),'DD.MM.YYYY HH24:MI:SS') from dual; -- â5 select to_char(to_date('03.02.2011 30', 'DD.MM.YYYY MI'),'DD.MM.YYYY HH24:MI:SS') from dual;
ãªã¯ãšã¹ãNo. 4ã§ã¯æéã¯ç€ºãããããªã¯ãšã¹ãNo. 5ã§ã¯åæ°ã®ã¿ã瀺ãããæéãšç§ã¯çç¥ãããŸãã Oracleã«ã¯ã«ãŒã«ããããæ¥ä»ã«æéã³ã³ããŒãã³ãããªãå ŽåãæéèŠçŽ ã®äžéšã®ã¿ãæå®ãããŠããå ŽåïŒã¯ãšãªNo.5ã®ããã«ïŒãæéã¯èªåçã«00:00:00ïŒã€ãŸãçå€äžïŒã«èšå®ãããèŠçŽ ã¯00ã«èšå®ãããŸãããããã£ãŠããªã¯ãšã¹ãçªå·4ã¯æååã03 .02.2011 00:00:00ããè¿ãããªã¯ãšã¹ãçªå·5ã¯ã03.03.02.2011 00:30:00ããè¿ããŸãã
ã¯ãšãª3ã«æ»ããŸãããããã®ã«ãŒã«ã¯æ¥ä»ã«åœãŠã¯ãŸããŸããã å€æäžã«æ¬ èœããæ¥ä»èŠçŽ ã¯00ãŸãã¯01ã«çœ®ãæããããŸããïŒ ã¯ãããããã¯çœ®ãæããããŸãããsysdateïŒçŸåšã®å¹Žã®çŸåšã®æã®æåã®æ¥ïŒããã®å€ããã¹ãŠæ¬ èœããŠããæ¥ä»èŠçŽ ã«äœ¿çšãããããã§ã¯ãããŸããã ãããã£ãŠããªã¯ãšã¹ãNo. 3ã¯æã09ã2011ã幎ãšããŠäœ¿çšããããããªã¯ãšã¹ãã®çµæã¯2011幎3æ9æ¥ãšãªããŸãã
äŸ2 ãã©ãŒãããé
次ã®ã¯ãšãªãå®è¡ãããŸããïŒå®è¡ãããå Žåãäœæ¥ç®ãè¿ãããŸããïŒ
-- â6 select to_date('20092011', 'YYYYDDMM') from dual;
äžèŠãæ¥ä»æååã«åºåãæåããªãããšã¯ãã¯ãšãªã®å®è¡ãšäºææ§ã®ãªãéèŠãªèŠçŽ ã®ããã«èŠããŸãããæ¥ä»ãã¹ã¯ãåºåãæåãªãã§æå®ãããå€æããæååã¯æå®ããããã¿ãŒã³ã«å¯Ÿå¿ããŸãã ãããã£ãŠããªã¯ãšã¹ãNo. 6ã¯æ£åžžã«å®è¡ããã2009幎11æ20æ¥ã«è¿éãããŸãïŒçµæã®åœ¢åŒã¯ãã»ãã·ã§ã³èšå®ã«ãã£ãŠãããã«ç°ãªãå ŽåããããŸãïŒã 次ã®äŸã§ãã»ãã¬ãŒã¿ã«é¢é£ããåé¡ããã詳现ã«æ€èšããŸãã
äŸ3 æé»çãªå€æ
ããã©ã«ãã®æ¥ä»åœ¢åŒãDD.MON.RRãæ¥ä»èšèªããã·ã¢èªãšãããšã次ã®ã¯ãšãªãæ©èœããŸãã
-- â7 select months_between('1\-9','01$/08') from dual;
ãã®ã¯ãšãªã¯ãæé»çãªå€æã䜿çšããŠæ¥ä»ã«å€æããå¿ èŠããã2ã€ã®æååãã©ã¡ãŒã¿ãŒãæå®ããŸãã ããã¥ã¡ã³ãã«ãããšãæ¢å®ã®åœ¢åŒã䜿çšããå Žåãæ¥ä»ãžã®æé»çãªå€æã®æååã¯ããã¿ãŒã³[D | DD] separator1 [MM | MON | MONTH] separator2 [R | RR | YY | YYYY]ãæºããå¿ èŠããããŸãã separator1ããã³separator2ãšããŠãã¹ããŒã¹ãã¿ããããã³ãäºéåŒçšç¬Šããå«ãã»ãšãã©ã®åºåãæåãšç¹æ®æåã䜿çšã§ããŸããããã«ãè¡ã«å°ãªããšã2æ¡ã®æ¥ãæã幎ãæå®ããå Žåã次ã«ãã»ãã¬ãŒã¿ãå®å šã«çç¥ããããšãã§ããŸããäŸïŒ
-- â8 select to_date('0109') from dual; -- â9 select to_date('0109') from dual; -- â10 DD.MM.RR select to_date('010909') from dual;
ã¯ãšãªNo. 7ã§æå®ãããäž¡æ¹ã®è¡ãæå®ããããã¿ãŒã³ã«å¯Ÿå¿ãããããã¯ãšãªã¯æ£åžžã«å®è¡ãããçªå·11ãè¿ãããŸãã
äŸçªå·4ã To_dateé¢æ°ã®ãã©ã¡ãŒã¿ãŒ
ããã©ã«ãã®æ¥ä»åœ¢åŒãDD.MON.RRãæ¥ä»èšèªããã·ã¢èªãšãããšã次ã®ã¯ãšãªãæ©èœããŸãã
-- â11 select to_date(sysdate,'mm/dd/yyyy hh24:mi:ss') from dual;
åæ§ã®ã¯ãšãªããAsk TomããŒãžã®è°è«ã®1ã€ã«ç»å ŽããŸããã èŠæ±ãã©ããã¯ãæ¥ä»ïŒsysdateïŒãæ¥ä»ã«å€æããããšããŠããããšã§ãã ãªã¯ãšã¹ãã次ã®ããã«ãªãå ŽåïŒ
-- â12 select to_char(sysdate,'mm/dd/yyyy hh24:mi:ss') from dual;
ãã®å®è¡ã¯æåããæåå'09 / 15/2011 23:00:11 'ãè¿ããŸããã ãã ããto_dateé¢æ°ã¯æåã®ãã©ã¡ãŒã¿ãŒãšããŠæååãæ³å®ããŠãããããæåã¯æ¥ä»ãæååã«æé»çã«å€æãããŸãïŒããã©ã«ãã®ãã¹ã¯ã§to_charïŒsysdateïŒãåŒã³åºãã®ãšåãã§ãïŒã ãã®å€æã®çµæã¯ã¹ããªã³ã°'15 .09.11 'ã§ãããto_dateåŒã³åºããè¡ãããŸãã ãããã£ãŠãã¯ãšãªïŒ11ã¯æ¬¡ã®ã¯ãšãªãšåçã§ãã
-- â13 select to_date('15.09.11','mm/dd/yyyy hh24:mi:ss') from dual;
è¡'15 .09.11 'ã¯ã€ã³ã¹ããŒã«ãããŠãããã¹ã¯ã«å¯Ÿå¿ããŠããªãããããªã¯ãšã¹ãNo. 13ãå®è¡ã§ããªãããšã確èªããããšã¯é£ãããããŸããããããã£ãŠããªã¯ãšã¹ãNo. 11ãå®è¡ã§ããŸããã
ããã©ã«ãã®æ¥ä»åœ¢åŒãèšå®ãã
ããã©ã«ãã®æ¥ä»åœ¢åŒã¯ãNLS_DATE_FORMATïŒåœ¢åŒèªäœã«è²¬ä»»ïŒãšNLS_DATE_LANGUAGEïŒæ¥ãæãªã©ã®ååãèšè¿°ãããšãã«äœ¿çšãããèšèªã«è²¬ä»»ïŒã®2ã€ã®ãã©ã¡ãŒã¿ãŒã«ãã£ãŠèšå®ãããŸãã ãããã®ãã©ã¡ãŒã¿ãŒãæ瀺çã«æå®ãããŠããªãå Žåããããã®å€ã¯NLS_LANGãã©ã¡ãŒã¿ãŒã«åºã¥ããŠèšå®ãããŸã ã
æ¥ä»åœ¢åŒãèšå®ã§ããã¬ãã«ã¯3ã€ãããŸãã
- DBã¬ãã«ïŒ
select * from nls_database_parameters where parameter in ('NLS_DATE_FORMAT','NLS_DATE_LANGUAGE');
- ã€ã³ã¹ã¿ã³ã¹ã¬ãã«ïŒ
select * from nls_instance_parameters where parameter in ('NLS_DATE_FORMAT','NLS_DATE_LANGUAGE');
- ã»ãã·ã§ã³ã¬ãã«ïŒ
select * from nls_session_parameters where parameter in ('NLS_DATE_FORMAT','NLS_DATE_LANGUAGE');
select SYS_CONTEXT ('USERENV', 'NLS_DATE_FORMAT'), SYS_CONTEXT ('USERENV', 'NLS_DATE_LANGUAGE') from dual;
create or replace trigger data_logon_trigger after logon ON DATABASE begin execute immediate 'alter session set nls_date_format = ''dd/mm/yyyy'''; end;
äŸ5 DD.MM.RRãšDD-MON-RRã®åœ¢åŒ
ããã©ã«ãã§æ¥ä»ã®ãã©ãŒãããã«æ³šæãæãããã«ãæååãæ¥ä»ã«æé»çã«å€æããéã®ããå¥åŠãªããšã«è§ŠçºãããŸããã 次ã®äŸãèŠãŠã¿ãŸãããã
-- â14 -- alter session set NLS_DATE_FORMAT='DD.MM.RR'; -- alter session set NLS_DATE_LANGUAGE='AMERICAN'; -- select * from nls_session_parameters where parameter in ('NLS_DATE_FORMAT','NLS_DATE_LANGUAGE'); -- select to_date('11.09.11') from dual; select to_date('11.SEP.11') from dual;
æåå'11 .09.11 'ã®æ¥ä»ãžã®å€æã¯æåããããæåå'11 .SEP.11'ã¯æåããªããšä»®å®ããã®ã¯è«ççã§ãã ãã ããããã§ã¯ãªããããäž¡æ¹ã®å€æãæ£åžžã«å®äºããŸãã æåã«ãæååãã»ãã·ã§ã³ãã¹ã¯ã«å€æã§ããªãå ŽåãOracleã¯ä»ã®ã¬ãã«ã®ãã¹ã¯ã䜿çšããããšãããšä»®å®ããŸããïŒDBã¬ãã«ãã¹ã¯ã¯ãDD-MON-RRãã«èšå®ãããŸãïŒã ããã¥ã¡ã³ããèªããšãããã§ã¯ãªãããšãããããŸãããOracleã¯ãåã®æ®µèœã§èª¬æããååã«åŸã£ãŠããŸãã
å¥ã®äŸãè©ŠããŠã¿ãŸãããã
-- â15 -- alter session set NLS_DATE_FORMAT='DD.MON.RR'; -- alter session set NLS_DATE_LANGUAGE='AMERICAN'; -- select * from nls_session_parameters where parameter in ('NLS_DATE_FORMAT','NLS_DATE_LANGUAGE'); -- select to_date('11.09.11') from dual; select to_date('11.SEP.11') from dual;
çµæãåã®ã¯ãšãªãšåãã ãšæãå Žåãããªãã¯ééã£ãŠããŸãã å€æã®1ã€ã倱æããŸãã ãã®å Žåãæåå'11 .09.11 'ã¯ãã¿ãŒã³ãšäžèŽããŸããã ããããããã¯ç¥ç§äž»çŸ©ã§ããããïŒ
ãããããã ããã¥ã¡ã³ããèªããšãæ¥ä»æžåŒèŠçŽ ã®èªå眮æã®ã«ãŒã«ãããããšãããããŸãã ã 以äžã¯äº€æè¡šã§ãã
å ã®ãã©ãŒãããèŠçŽ | ãªãªãžãã«ã®ä»£ããã«è©Šãè¿œå ã®ãã©ãŒãããèŠçŽ |
---|---|
ãMMã | ãæããšãæã |
ãæ | ãæã |
ãæã | ãæã |
ãYyã | ãYYYYã |
ãRRã | ãRRRRã |
äŸ6 ãã©ãŒãããRR vs YY
ã»ãšãã©ã®ãŠãŒã¶ãŒã«ãšã£ãŠãRRãã¹ã¯ãšYYãã¹ã¯ã®éãã¯ããç¥ãããŠããŸããããã®æ å ±ã圹ç«ã€ãšæãã人ãããŸãã äŸã®æ€èšã«ããã«é²ã¿ãŸãã 次ã®ã¯ãšãªãè¿ãããŒã¿ïŒ
-- â16 select to_date('11','RR') "RR", to_date('11','YY') "YY" from dual; -- â17 select to_date('99','RR') "RR", to_date('99','YY') "YY" from dual;
äžèšã®äž¡æ¹ã®ãªã¯ãšã¹ãã¯æåãããªã¯ãšã¹ãNo. 3ã®äŸNo. 1ã«èšèŒãããŠããã«ãŒã«ã«åŸã£ãŠæ¥ä»ãè¿ããŸãã ãããã£ãŠãåä¿¡ãããã¹ãŠã®æ¥ä»ã®æ¥ã®å€ã¯01ã«ãªããæã®å€ã¯09ã«ãªããŸãïŒ9æã«ãªã¯ãšã¹ããå®è¡ããå ŽåïŒã äž»ãªè³ªåã¯ãä»å¹Žã®éèŠæ§ã¯äœã§ããïŒ
ã¯ãšãªNo. 16 by '11'ã§ã¯2011幎ãæå³ããäž¡æ¹ã®ãã¹ã¯ããããç§ã«è¿ãããšæšæž¬ããã®ã¯ç°¡åã§ãã ã¯ãšãªïŒ16ã®çµæã¯ã2011幎9æ1æ¥ãš2011幎9æ1æ¥ã§ãã
ãªã¯ãšã¹ãNo. 17ã§ã¯ã'99 'ã§1999ãæå³ããŸããããããã§ã¯ãã¹ã¯ã®æèŠãåãããŠããŸãããRRãã¹ã¯ã¯äºæ³ããã1999ãè¿ããYYãã¹ã¯ã¯2099ãè¿ããŸããã ã¯ãšãªïŒ17ã®çµæã¯1999幎9æ1æ¥ãš2099幎9æ1æ¥ã§ãã
ãããã®ãã©ãŒãããèŠçŽ ãã©ã®ããã«æ©èœãããã詳ããèŠãŠã¿ãŸãããã
-- â18 select to_date('00','RR') "00", to_date('49','RR') "49", to_date('50','RR') "50", to_date('99','RR') "99" from dual union all select to_date('00','YY') "00", to_date('49','YY') "49", to_date('50','YY') "50", to_date('99','YY') "99" from dual;
ã¯ãšãªçªå·18ãããããããã«ããã¹ã¯ã®åäœã®éãã¯50幎代ããå§ãŸããŸãã YY圢åŒã¯åžžã«çŸåšã®äžçŽã®å¹Žãè¿ããRRã¯ãçŸåšã®äžçŽã®å¹ŽãšããŠ50幎æªæºãããã³åäžçŽã®å¹ŽãšããŠ50幎以äžã®å¹ŽãèªèããŸãã å®éãå€to_dateïŒ'99 'ã' RR 'ïŒ= 1999ããã³to_dateïŒ' 00 'ã' RR 'ïŒ= 2000ã¯ãçŸåšã®æ¥ä»ã2051æªæºã§ããã®åŸã«to_dateïŒ'99'ã 'RR' ïŒ= 2099ããã³to_dateïŒ'00 'ã' RR 'ïŒ=2100ãå®éšããå ŽåããµãŒããŒæéã2051ã«å€æŽããã¯ãšãªïŒ18ã®çµæãã©ã®ããã«å€åãããã確èªã§ããŸããå®è¡äžã®ã·ã¹ãã ã§ã¯å®è¡ããªãã§ãã ããã ãµãŒããŒæéãå€æŽããããšãsysdateãå€æŽãããããããã¹ãŠã®ã¬ããŒãããã°ããŒãã«ãªã©ã§çºçããé çã®çš®ã«ã€ããŠãèããªãæ¹ãããã§ãããã RR圢åŒã䜿çšããŠ2æ¡ã®å¹Žã4æ¡ã®å¹Žã«å€æããããã®äžè¬çãªèŠåã¯æ¬¡ã®ããã«ãªããŸã ã
æå®ããã2æ¡ã®å¹Žã00ã49ã®å Žåã
- çŸåšã®å¹Žã®äž2æ¡ã00ãã49ã®å Žåãè¿ããã幎ã®æåã®2æ¡ã¯çŸåšã®å¹Žãšåãã«ãªããŸãã
- çŸåšã®å¹Žã®äž2æ¡ã50ã99ã®å Žåãè¿ããã幎ã®äž2æ¡ã¯ãçŸåšã®å¹Žã®äž2æ¡ããã1倧ãããªããŸãã
- çŸåšã®å¹Žã®äž2æ¡ã00ãã49ã®å Žåãè¿ããã幎ã®æåã®2æ¡ã¯ãçŸåšã®å¹Žã®äž2æ¡ããã1å°ãªããªããŸãã
- çŸåšã®å¹Žã®äž2æ¡ã50ãã99ã®å Žåãè¿ããã幎ã®æåã®2æ¡ã¯çŸåšã®å¹Žãšåãã«ãªããŸãã
-- â19 select to_date('1950','RR') "50RR", to_date('1950','YY') "50YY" from dual;
ãããã£ãŠããªã¯ãšã¹ã19ã¯ãã©ã¡ãã®å Žåã1950ãè¿ããŸãã
äŸ7 ä»ã®ããã€ãã®äŸ
ã¬ãã¥ãŒãçµäºããã«ã¯ãå°ãç°åœæ ç·ãèæ ®ããŠãã ããã 次ã®ã¯ãšãªã®çµæãšããŠãšã©ãŒãçºçããŸããïŒ
-- â20 select DATE '1928-12-25' from dual;
ãããç¡æå³ãªã¬ã³ãŒãã§ãããšå€æããå Žåã¯ãééããããŸããããã¯ANSIæšæºã«æºæ ããå®å šã«æ£ããæ¥ä»èšå®ã§ãããã¯ãšãªNo. 20ã¯æåãã1928幎12æ25æ¥ã«è¿ãããŸãã
ã©ã®ãªã¯ãšã¹ãã倱æããŸããïŒ
-- â21 select to_date('1998--25 17:30','YYYY-MON-DD HH24:MI','NLS_DATE_LANGUAGE=AMERICAN') from dual; -- â21 select to_date('1998--25 17:30','YYYY-MON-DD HH24:MI','NLS_DATE_LANGUAGE=RUSSIAN') from dual;
ãã®äŸã¯ãto_dateé¢æ°ã®3çªç®ã®ãã©ã¡ãŒã¿ãŒã®ååšã瀺ãããšãç®çãšããŠããŸãã ãã®ãã©ã¡ãŒã¿ãŒã䜿çšãããšããã®to_dateé¢æ°åŒã³åºãã«å¯ŸããŠã®ã¿ãNLSïŒNational Language SupportïŒãã©ã¡ãŒã¿ãŒã®ããããã®å€ãèšå®ã§ããŸãã äŸ5ã§æ€èšããã»ãã·ã§ã³ã®NLSãã©ã¡ãŒã¿ãŒãèšå®ããŸãã ãªã¯ãšã¹ãNo. 20ãšNo. 21ã®äž»ãªéãã¯ãæã®ååã§ã¯ãªãïŒäŸ5ã§èª¬æãããŠããããã«ãMONãã¹ã¯ã¯èªåçã«MONTHãã¹ã¯ã«çœ®ãæããããŸãïŒãç°ãªãæ¥ä»èšèªã瀺ããŠããŸãã ãªã¯ãšã¹ãçªå·21ã¯æã®ååãè±èªã§æåŸ ããŠãããããå®è¡ãããŸãã;ãªã¯ãšã¹ãçªå·22ã¯æã®ååããã·ã¢èªã§æåŸ ããæ£åžžã«å®è¡ãããŸãã
次ã®ããŒãã«å®£èšã¯ãã©ã®ãããªå Žåã«ããŒã¿ãæ¿å ¥ãããšãã«ãšã©ãŒã«ã€ãªããå¯èœæ§ããããŸããïŒ
-- â23 create table for_test (a number, b date default to_date('11.09.2011'));
ããã©ã«ãã®æ¥ä»åœ¢åŒãDD.MON.RRãã®ã»ãã·ã§ã³ã§ã¯ãæåã®åã®å€ã®ã¿ãæ¿å ¥ããããã³ã«
insert into for_test(a) values(1);
ãšã©ãŒãçºçããŸãã
ããŸããŸãªã¢ããªã±ãŒã·ã§ã³ã§æ¥ä»ã衚瀺ããæ©èœ
æ¥ä»è¡šç€ºã«åœ±é¿ãããã®
ãã®ã»ã¯ã·ã§ã³ã¯ãã³ã¡ã³ãã«ç€ºãããæšå¥šäºé ã«ãããèšäºã®çºè¡åŸã«è¿œå ãããŸããã 以äžã¯ãæ¥ä»ã®è¡šç€ºãšæ°å€ã®è¡šç€ºã®äž¡æ¹ã«åœãŠã¯ãŸããŸãã ãããããäžèšã®èšäºã«èšèŒãããŠããããã€ãã®äŸãå®è¡ãããšãçµæã«ç€ºãããŠãã圢åŒä»¥å€ã®åœ¢åŒã§æ¥ä»ãåãåããŸããã ã»ãã·ã§ã³ã®èšå®ãäŸã«ç€ºãããŠãããšããã§ããã°ãããã¯å°ãªããšãå¥åŠã«æããŸãã
çå®ã¯ããªã¯ãšã¹ããå®è¡ãããšã
-- â24 select sysdate from dual;
æ¥ä»ãååŸããŸãããç»é¢ã«çµæã衚瀺ããã«ã¯ãããŒã¿ããŒã¹ã«ã¢ã¯ã»ã¹ããç¹å®ã®ãŠãŒãã£ãªãã£ãæ¥ä»ãæååã«å€æããå¿
èŠããããŸãã ãããã£ãŠãæ¥ä»ïŒããã³æ°å€ïŒã衚瀺ããã«ã¯ãto_charãæé»çã«åŒã³åºãããŸãã æé»çãªå€æã®å€å
žçãªã±ãŒã¹ããããŸãïŒãã®å€æã¯ç»é¢ã«è¡šç€ºããããã ãã§ããããã®çµæã¯èšç®ã«é¢äžãããããŒã¿ã®è¡šç€ºä»¥å€ã«ã¯åœ±é¿ããŸããïŒã æé»çãªå€æãããå Žåããããå®è¡ãããã¹ã¯ããããŸãã å€å
žçãªã±ãŒã¹ã§ã¯ãã»ãã·ã§ã³ã«èšå®ããããã¹ã¯ãã€ãŸã nls_session_parametersããŒãã«ã®NLS_DATE_FORMATãã©ã¡ãŒã¿ãŒã§æå®ããããã¹ã¯ãããã¯èšäºå
šäœã§ç©æ¥µçã«äœæ¥ããŸããã
ããã€ãã®ã¢ããªã±ãŒã·ã§ã³ã®åäœã確èªããŸãããã 次ã®ã¹ã¯ãªããã䜿çšããŠç¢ºèªããŸãã
-- â25 -- select * from nls_session_parameters where parameter in ('NLS_DATE_FORMAT','NLS_DATE_LANGUAGE'); -- select sysdate from dual; -- alter session set NLS_DATE_FORMAT='DD.MON.RR hh24:mi:ss'; -- select sysdate from dual;
sqlplusãæ¥ä»ã®è¡šç€ºã«äœ¿çšãããã©ã¡ãŒã¿ãŒã確èªããŸãããã
å³ 1. sqlplusã®ã¯ãšãªïŒ25ã®çµæã
å³1ãããããããã«ãæ¥ä»è¡šç€ºåœ¢åŒã¯ã»ãã·ã§ã³èšå®ãã€ãŸã sqlplusã¯ã»ãã·ã§ã³èšå®ã䜿çšããŸãã ããã«ãããå€æãšè¡šç€ºã®äž¡æ¹ã«åããã¹ã¯ã䜿çšããããããæ¥ä»ãæååã«ããŸãã¯ãã®éã«å€æããããã»ã¹ãç解ãããããªããŸãã
äžéšã®é«åºŠãªéçºããŒã«ã¯ãOracleèšå®ã«é¢é£ããªãç¬èªã®NLSèšå®ã䜿çšããŸãã äŸãšããŠãæ¥ä»ã衚瀺ããããã«PL / SQL Developerã䜿çšãããªãã·ã§ã³ã確èªããŸãããã ãããè¡ãã«ã¯ããªã¯ãšã¹ãçªå·25ãå®è¡ããŸãã
å³ 2. PL / SQL Developerã®ã¯ãšãªïŒ25ã®çµæã
å³2ãããããããã«ãã»ãã·ã§ã³èšå®ãå€æŽããŠãæ¥ä»è¡šç€ºåœ¢åŒã¯å€ãããŸããã ããã«ã泚ææ·±ãèŠããšãç»é¢ã«æ¥ä»ãè¡šââ瀺ããæåãš2çªç®ã®çµæãã»ãã·ã§ã³ãã©ã¡ãŒã¿ãŒãšäžèŽããªãã£ãããšãããããŸãïŒæåã®å Žåã衚瀺ãããæ¥ä»ã¯4æ¡åœ¢åŒã®å¹Žã§ããã¹ã¯ã¯2æ¡åœ¢åŒã®å¹Žã瀺ããŠããŸããïŒã ããã¯ããŠãŒãã£ãªãã£ãç¬èªã®NLSèšå®ã䜿çšããããšãæå³ããŸããPL/ SQL Developerã®å Žåããã®å Žæã¯å³ã«ç€ºãããŠããŸãã 3ã
å³ 3. PL / SQL Developerã§NLSæ¥ä»è¡šç€ºãªãã·ã§ã³ãèšå®ããŸãã
NLSãŠãŒãã£ãªãã£ã®èšå®ãæªãããšãããæ¹æ³
ã»ãã·ã§ã³åœ¢åŒãšã¯ç°ãªã圢åŒã§æ¥ä»ã衚瀺ãããšã1ã€ã®çç±ã§æ害ã§ã-ãŠãŒã¶ãŒã誀解ããããšã©ãŒãåŒãèµ·ããå¯èœæ§ããããŸãã sqlplusããã³PL / SQL Developerã§æ¬¡ã®ã¯ãšãªãå®è¡ããŸãã
-- â26 -- alter session set NLS_DATE_FORMAT='DD.MON.RR hh24:mi:ss'; -- select sysdate from dual; -- select to_date() from dual;
ã®ä»£ããã«ãåã®è¡ããåä¿¡ããããŒã¿ãã¯ãšãªã®æåŸã®è¡ã«æ¿å
¥ããŸãã
ã¯ãšãªã®çµæã¯ã以äžã®å³ã«ç€ºãããŠããŸãã
å³ 4. sqlplusã®ã¯ãšãªïŒ26ã®çµæã
å³ 5. PL / SQL Developerã®ã¯ãšãªïŒ26ã®çµæã
sqlplusã§è¡šç€ºãããããŒã¿ãæ£åžžã«æ¥ä»ã«å€æãããPL / SQL Developerã«ãã£ãŠè¡šç€ºãããããŒã¿ãå€æã§ããªãã£ãã®ã¯ãªãã§ããïŒ Oracleã¯ã»ãã·ã§ã³ã§æå®ãããããŒã¿åœ¢åŒãå€æã«äœ¿çšããPL / SQL Developerã«ããããŒã¿åºåã¯ã»ãã·ã§ã³åœ¢åŒãšã¯ç°ãªãç¬èªã®åœ¢åŒã§è¡šç€ºãããããã§ãã
ãããã«
çµè«ãšããŠãæ¥ä»ã®æäœã«å°å¿µããã»ãŒãã¹ãŠã®æçš¿ã§ãTom Kiteã¯æ瀺çãªå€æã䜿çšããå¿ èŠæ§ãšãã¹ã¯ã®å¿ é 䜿çšã«ã€ããŠè©±ããŠããããšãæãåºããŠãã ããã ãæååãæ¥ä»ã«å€æãããšãã¯ãããã©ã«ãã®æ¥ä»åœ¢åŒã«äŸåãããåžžã«æ瀺çã«ãã¹ã¯ãèšå®ããŠãã ããã-ããã圌ã®èšèã®çºé³ã§ãã ask TomããŒãžã䜿çšããŠãæ¥ä»å€æãæäœãããšãã«ãè¿œå ã®äŸãšèãããããšã©ãŒãèŠã€ããããšãã§ããŸãã
æ¥ä»ãæ±ãããšã¯èšäºå šäœãåãäžããã®ã§ãå€ãã®èå³æ·±ã質åãããªãŒããŒããŒããã®ãŸãŸã§ããããããæ€èšããããšæããŸãã ã»ãšãã©ã®å Žåãèšäºã®3çªç®ã®éšåã¯ã空ãæéããããšããã«è¡šç€ºãããŸãã