sql ¹® Áú¹®µå¸³´Ï´Ù.

   Á¶È¸ 2545   Ãßõ 0    

 마리아 db 

SELECT DATE_ADD(STR_TO_DATE('2015-04-08','%Y-%m-%d'), INTERVAL seq HOUR) AS hh  FROM seq_0_to_99


이것을 오라클로  바꾸면 어떻게 될까요?

이지포토
ªÀº±Û Àϼö·Ï ½ÅÁßÇÏ°Ô.
±èµ¿¼öP 2019-07
select to_date('2015-04-08','YYYY-mm-dd') + (seq/24) as hh from seq_0_to_99

ÀÌ·± ´À³¦Àϱî¿ä? ^^
     
´ëÃæ ¸Â¾Ò´Âµ¥ seq_0_to_99°¡ Å×À̺íÀÌ ¾Æ´Ï¶ó¼­¿ä. °¨»ç ÇÕ´Ï´Ù.
´À³¦»ó seq_0_to_99 ÀÌ°Ç º¸´Ï 0ºÎÅÍ 99±îÁö ½ÃÄö¼ÈÇÏ°Ô row´ÜÀ§·Î ³ª¿À°Ô ÇÏ·ÁÇϴµíÇÏ¿©...

SELECT
            TO_CHAR(TO_DATE('2015-04-08', 'YYYY-MM-DD')+ROWNUM/24, 'HH') AS HH -- ´Ü¼ø ½Ã°£À» HH·Î »Ì°í ½Í¾îÇÏ½Ã´Â°Í °°¾Æ¼­...
FROM    DUAL
CONNECT BY LEVEL <= 100;

À̰Űڳ׿ä...
     
°¨»ç ÇÕ´Ï´Ù.
     
SELECT ROWNUM, TO_CHAR(add_months( (sysdate), interval + ROWNUM*(1/60)*(1/24) HOUR ),'YYYY-MM-DD HH24:MI:SS')  FROM     DUAL
CONNECT BY LEVEL <= 100
 ÀÌ°Ô ¿Ö ¾ÈµÇ´ÂÁö Áú¹®µå·Áµµ µÉ±î¿ä?
          
Àǵµ¸¦ Á¤È®È÷ ¾Ë°í ½Í³×¿ä...

SELECT
        ROWNUM                            AS RN
,      SYSDATE+(ROWNUM-1)/24            AS VAL1 -- ½Ã°£´ÜÀ§·Î Áõ°¡½ÃÅ°±â
,      SYSDATE+(ROWNUM-1)                AS VAL2 -- ÇöÀ糯¥ Æ÷ÇÔ ÇϷ羿 Áõ°¡½ÃÅ°±â
,      ADD_MONTHS(SYSDATE, (ROWNUM-1))  AS VAL3 -- ÇÑ´Þ¾¿ Áõ°¡½ÃÅ°±â
,      ADD_MONTHS(SYSDATE, (ROWNUM-1)/5) AS VAL4 -- 5°³ÀÇ ROW´Â Ç×»ó °°°í, ±× ´ÙÀ½ 5°³ ROW´Â +1MONTHÇϱâ
FROM    DUAL
CONNECT BY LEVEL <= 100
;

´ëÃæ ÀÌ·± ´À³¦ÀÌ·Á³ª¿ä?
               
2015-04-08 00:00:00
2015-04-08 01:00:00
2015-04-08 02:00:00
2015-04-08 03:00:00
2015-04-08 04:00:00
 ÀÌ·±·Î¿ì¸¦ »Ì±â¸¸ ÇϸéµË´Ï´Ù.
               
SELECT
        ROWNUM                            AS RN
,      to_date(SYSDATE+(ROWNUM-1)/24 ,'YYYY-MM-DD HH24:MI:SS')  AS VAL1 -- ½Ã°£´ÜÀ§·Î Áõ°¡½ÃÅ°±â

FROM    DUAL
CONNECT BY LEVEL <= 100 
ÀÌ·¸°ÔÇصµ ½Ã°£Àº ¾È³ª¿À³×¿ä.Áß¿äÇÑ°ÍÀº data type À¸·Î ½Ã°£ÀÌ ³ª¿Í¾ßÇϴµ¥¿ä.
                    
DATE TYPEÀ» ´Ù½Ã DATE TYPEÀ¸·Î º¯È¯Çϸ鼭 ¹®Á¦°¡ ¹ß»ýÇ߳׿ä.
SELECT
        ROWNUM                            AS RN
,      TRUNC(SYSDATE)+(ROWNUM-1)/24      AS VAL1 -- ½Ã°£´ÜÀ§·Î Áõ°¡½ÃÅ°±â (DATE TYPE)
,      TO_CHAR(TRUNC(SYSDATE)+(ROWNUM-1)/24, 'YYYY-MM-DD HH24:MI:SS')        AS VAL2 -- ½Ã°£´ÜÀ§·Î Áõ°¡½ÃÅ°±â (CHAR TYPE)
FROM    DUAL
CONNECT BY LEVEL <= 100
;
ÀÌ·¸°Ô ÇÏ¸é ¾Æ·¡¿Í °°Àº °á°ú°ªÀÌ ³ª¿É´Ï´Ù.
RN VAL1                         VAL2
1 2019/07/25 00:00:00 2019-07-25 00:00:00
2 2019/07/25 01:00:00 2019-07-25 01:00:00
3 2019/07/25 02:00:00 2019-07-25 02:00:00
4 2019/07/25 03:00:00 2019-07-25 03:00:00
5 2019/07/25 04:00:00 2019-07-25 04:00:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96 2019/07/28 23:00:00 2019-07-28 23:00:00
97 2019/07/29 00:00:00 2019-07-29 00:00:00
98 2019/07/29 01:00:00 2019-07-29 01:00:00
99 2019/07/29 02:00:00 2019-07-29 02:00:00
100 2019/07/29 03:00:00 2019-07-29 03:00:00


QnA
Á¦¸ñPage 1239/5680
2014-05   4946937   Á¤ÀºÁØ1
2015-12   1483593   ¹é¸Þ°¡
2020-06   2905   Platinum
2021-11   2283   ½º¿þÀÎ
2023-06   2564   ´ÙÃʸ°
2013-03   5995   Á¤¸íÈÆ
2014-09   3923   À嵿°Ç2014
2020-06   5742   µ¶Å丣µ§
2023-06   2050   ¹Ì¼ö¸Ç
2018-02   4527   ±è°Ç¿ì
2016-12   4800   ¹éµÎ¼º
2021-11   2891   ¹è°íÇÁ°í°¡¡¦
2021-11   1414   ´Ù´Ï¿¤Çìµù
2020-06   2255   Sakura24
2014-09   10589   ³ªºñz
2020-06   6101   ´ÙÀ̾îÆ®Áß
2010-02   10409   ÄÚ»Ô»ç³É
2020-07   2621   °¡ºü·Î±¸³ª
2023-07   2112   ĸƾ¾Æ¸Þ¸®Ä«³ë
2010-02   9017   ¹ÚÁ¾ÀÍ
2016-12   4170   ¾ËÆÄ°í
2020-07   2348   ¼ÛÁøÇö