출처 : http://dbdbdic.tistory.com/112
CREATE TABLE TEMP_DATE( ID INT, INDATE DATETIME ) INSERT INTO TEMP_DATE (ID, INDATE ) SELECT '1', SYSDATE FROM OPENQUERY(ORACLE_LINK,'SELECT SYSDATE FROM DUAL') SELECT * FROM TEMP_DATE -- 날짜 08 22 2006 의 형식을 2006-08-22 00:00:00 으로 변경하기 SELECT @t_PLAN_STARTDATE = CAST(@Plan_StartDate AS DATETIME ) SELECT @t_PLAN_ENDDATE = CAST(@Plan_EndDate AS DATETIME )
Oracle - MS SQL - DB2 UDB 의 서로 다른 날짜 형식을 맞추기위한 SQL문
1. Oracle
날짜+시분초 까지 조회가능
SELECT sysdate FROM dual; -- 날짜+밀리초+시간존 까지 조회 SELECT CURRENT_TIMESTAMP FROM dual;
2. MS SQL
-- 날짜 + 밀리초 단위까지 조회가능 SELECT getdate();
3. DB2 UDB
-- 날짜+밀리초까지 조회 가능 SELECT CURRENT TIMESTAMP FROM sysibm.sysdummy1; -- 날짜만 조회 SELECT CURRENT DATE FROM sysibm.sysdummy1; -- 밀리초 단위의 시간만 조회 SELECT CURRENT TIME FROM sysibm.sysdummy1;
1. Oracle
한글 : YYYY/MM/DD | 영어 : DD-MON-YYYY |
2. MS SQL
한글 : YYYY/MM/DD HH:MI:SS | 영어 : MM-DD-YYYY HH:MI:SS |
3. DB2 UDB
TIMESTAMP 타입 : YYYY-MM-DD-HH:MI:SS.MMMMMM |
DATE 타입 : YYYY-MM-DD |
TIME 타입 : HH:MI:SS.MMMMMM |
[ 형식 : 'YYYY.MM.DD' ]
-- Oracle TO_CHAR(date_exp, 'YYYY.MM.DD') -- MSSQL CONVERT(VARCHAR, date_exp, 102) -- DB2 REPLACE(CHAR(DATE(date_exp),ISO), '-', '.')
[ 형식 : 'HH:MI:SS' ]
-- Oracle TO_CHAR(date_exp, 'HH:MI:SS') -- MSSQL CONVERT(VARCHAR, date_exp, 108) -- DB2 CHAR(TIME(date_exp) , JIS )
[ 형식 : 'YYYY/MM/DD' ]
-- Oracle TO_CHAR(date_exp, 'YYYY/MM/DD') -- MSSQL CONVERT(VARCHAR, date_exp, 111) -- DB2 REPLACE(CHAR(DATE(date_exp), ISO), '-', '/')
[ 형식 : 'YYYYMMDD' ]
-- Oracle TO_CHAR(date_exp, 'YYYYMMDD') | -- MSSQL CONVERT(VARCHAR, date_exp, 112) | -- DB2 CHAR(DATE(date_exp)) |
[ 형식 : 'HH24:MI:SS' ]
-- Oracle TO_CHAR(date_exp, 'HH24:MI:SS') | -- MSSQL CONVERT(VARCHAR(8), date_exp, 114) | -- DB2 CHAR(TIME(date_exp)) |
[ 형식 : 'YYYY.MM.DD HH24:MI' ]
-- Oracle TO_CHAR(date_exp, 'YYYY.MM.DD HH24:MI') -- MSSQL CONVERT(VARCHAR, date_exp, 102) + ' ' + CONVERT(VARCHAR(5), date_exp, 114) -- DB2 REPLACE(CHAR(DATE(date_exp), ISO), '-', '.') || CAST( TIME(date_exp) AS CHAR(5))
[ 형식 : 'YYYY/MM/DD HH24:MI:SS' ]
-- Oracle TO_CHAR(date_exp, 'YYYY/MM/DD HH24:MI:SS') -- MSSQL CONVERT(VARCHAR, date_exp, 111) + ' ' + CONVERT(VARCHAR(8), date_exp, 114) -- DB2 REPLACE(CHAR(DATE(date_exp), ISO), '-', '/') || CAST( TIME(date_exp))