반응형
Oracle 과 Mssql 날짜비교 함수
CREATE TABLE TEMP_DATE
( ID INT,
INDATE DATETIME )
( ID INT,
INDATE DATETIME )
INSERT INTO TEMP_DATE (ID, INDATE )
SELECT '1', SYSDATE FROM OPENQUERY(ORACLE_LINK,'SELECT SYSDATE FROM DUAL')
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 )
SELECT @t_PLAN_STARTDATE = CAST(@Plan_StartDate AS DATETIME )
SELECT @t_PLAN_ENDDATE = CAST(@Plan_EndDate AS DATETIME )
### DBMS에 따른 날짜포맷 변환 ###
Oracle - MS SQL - DB2 UDB 의 서로 다른 날짜 형식을 맞추기위한 SQL문
--------------------------------------------------------------------------------
DBMS 별 시간, 날짜 조회 쿼리
--------------------------------------------------------------------------------
1. Oracle
- 날짜+시분초 까지 조회가능
select sysdate from dual;
DBMS 별 시간, 날짜 조회 쿼리
--------------------------------------------------------------------------------
1. Oracle
- 날짜+시분초 까지 조회가능
select sysdate from dual;
- 날짜+밀리초+시간존 까지 조회
select current_timestamp from dual;
2. MS SQL
- 날짜 + 밀리초 단위까지 조회가능
select getdate();
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;
--------------------------------------------------------------------------------
DBMS 별 default date format
--------------------------------------------------------------------------------
1. Oracle
한글 : YYYY/MM/DD 영어 : DD-MON-YYYY
- 날짜+밀리초까지 조회 가능
select current timestamp from sysibm.sysdummy1;
- 날짜만 조회
select current date from sysibm.sysdummy1;
- 밀리초 단위의 시간만 조회
select current time from sysibm.sysdummy1;
--------------------------------------------------------------------------------
DBMS 별 default date format
--------------------------------------------------------------------------------
1. Oracle
한글 : YYYY/MM/DD 영어 : DD-MON-YYYY
2. MS SQL
한글 : YYYY/MM/DD HH:MI:SS 영어 : MM-DD-YYYY HH:MI:SS
한글 : 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
TIMESTAMP 타입 : YYYY-MM-DD-HH:MI:SS.MMMMMM
DATE 타입 : YYYY-MM-DD
TIME 타입 : HH:MI:SS.MMMMMM
--------------------------------------------------------------------------------
날짜 포맷 변환
--------------------------------------------------------------------------------
[ 형식 : 'YYYY.MM.DD' ]
1. Oracle : TO_CHAR(date_exp, 'YYYY.MM.DD')
2. MSSQL : CONVERT(VARCHAR, date_exp, 102)
3. DB2 : REPLACE(CHAR(DATE(date_exp),ISO), '-', '.')
[ 형식 : 'HH:MI:SS' ]
1. Oracle : TO_CHAR(date_exp, 'HH:MI:SS')
2. MSSQL : CONVERT(VARCHAR, date_exp, 108)
3. DB2 : CHAR(TIME(date_exp) , JIS )
날짜 포맷 변환
--------------------------------------------------------------------------------
[ 형식 : 'YYYY.MM.DD' ]
1. Oracle : TO_CHAR(date_exp, 'YYYY.MM.DD')
2. MSSQL : CONVERT(VARCHAR, date_exp, 102)
3. DB2 : REPLACE(CHAR(DATE(date_exp),ISO), '-', '.')
[ 형식 : 'HH:MI:SS' ]
1. Oracle : TO_CHAR(date_exp, 'HH:MI:SS')
2. MSSQL : CONVERT(VARCHAR, date_exp, 108)
3. DB2 : CHAR(TIME(date_exp) , JIS )
[ 형식 : 'YYYY/MM/DD' ]
1. Oracle : TO_CHAR(date_exp, 'YYYY/MM/DD')
2. MSSQL : CONVERT(VARCHAR, date_exp, 111)
3. DB2 : REPLACE(CHAR(DATE(date_exp), ISO), '-', '/')
1. Oracle : TO_CHAR(date_exp, 'YYYY/MM/DD')
2. MSSQL : CONVERT(VARCHAR, date_exp, 111)
3. DB2 : REPLACE(CHAR(DATE(date_exp), ISO), '-', '/')
[ 형식 : 'YYYYMMDD' ]
1. Oracle : TO_CHAR(date_exp, 'YYYYMMDD')
2. MSSQL : CONVERT(VARCHAR, date_exp, 112)
3. DB2 : CHAR(DATE(date_exp))
1. Oracle : TO_CHAR(date_exp, 'YYYYMMDD')
2. MSSQL : CONVERT(VARCHAR, date_exp, 112)
3. DB2 : CHAR(DATE(date_exp))
[ 형식 : 'HH24:MI:SS' ]
1. Oracle : TO_CHAR(date_exp, 'HH24:MI:SS')
2. MSSQL : CONVERT(VARCHAR(8), date_exp, 114)
3. DB2 : CHAR(TIME(date_exp))
1. Oracle : TO_CHAR(date_exp, 'HH24:MI:SS')
2. MSSQL : CONVERT(VARCHAR(8), date_exp, 114)
3. DB2 : CHAR(TIME(date_exp))
[ 형식 : 'YYYY.MM.DD HH24:MI' ]
1. Oracle : TO_CHAR(date_exp, 'YYYY.MM.DD HH24:MI')
2. MSSQL : CONVERT(VARCHAR, date_exp, 102) + ' ' + CONVERT(VARCHAR(5), date_exp, 114)
3. DB2 : REPLACE(CHAR(DATE(date_exp), ISO), '-', '.') || CAST( TIME(date_exp) AS CHAR(5))
1. Oracle : TO_CHAR(date_exp, 'YYYY.MM.DD HH24:MI')
2. MSSQL : CONVERT(VARCHAR, date_exp, 102) + ' ' + CONVERT(VARCHAR(5), date_exp, 114)
3. DB2 : REPLACE(CHAR(DATE(date_exp), ISO), '-', '.') || CAST( TIME(date_exp) AS CHAR(5))
[ 형식 : 'YYYY/MM/DD HH24:MI:SS' ]
1. Oracle : TO_CHAR(date_exp, 'YYYY/MM/DD HH24:MI:SS')
2. MSSQL : CONVERT(VARCHAR, date_exp, 111) + ' ' + CONVERT(VARCHAR(8), date_exp, 114)
3. DB2 : REPLACE(CHAR(DATE(date_exp), ISO), '-', '/') || CAST( TIME(date_exp))
1. Oracle : TO_CHAR(date_exp, 'YYYY/MM/DD HH24:MI:SS')
2. MSSQL : CONVERT(VARCHAR, date_exp, 111) + ' ' + CONVERT(VARCHAR(8), date_exp, 114)
3. DB2 : REPLACE(CHAR(DATE(date_exp), ISO), '-', '/') || CAST( TIME(date_exp))
[출처] Oracle 과 Mssql 날짜비교 함수 |작성자 메주
반응형
'ORACLE > SQL' 카테고리의 다른 글
단일 행 함수 (0) | 2008.11.24 |
---|---|
oracle vs ms-sql 함수 비교 (0) | 2008.11.24 |
RTRIM (0) | 2008.11.24 |
Oracle 날짜 관련 함수 (0) | 2008.10.29 |
Oracle 날짜형 데이터의 연산 (0) | 2008.06.17 |