Background Image
조회 수 18909 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

○ 날짜 컬럼을 문자(char, varchar)로 설계
  문자로 설계한 날짜 컬럼에서 날짜형식으로 변경하면 쿼리 에러가 발생 함.  (예 : 20120132, 20110a03 등)

 

○ 해결방법
  - 데이터 입력시점에 정확한 날짜 데이터만 들어가도록 함
  - 기존의 오류 데이터는 사용자정의 함수를 작성하여 데이터를 찾고, 변환 함


○ 테스트 테이블생성
   - create table tmp_test(tmp_date varchar(8));

 

○ 테스트 데이터 
insert into tmp_test VALUES('20120108');
insert into tmp_test VALUES('20120109');
insert into tmp_test VALUES('20120110');
insert into tmp_test VALUES('20120111');
insert into tmp_test VALUES('20120112');
insert into tmp_test VALUES('20120113');
insert into tmp_test VALUES('20120114');
insert into tmp_test VALUES('20120115');
insert into tmp_test VALUES('20120132');


○ 오류 확인(날짜 관련 함수 사용 불가), 어떤 데이타가 오류이지 확인불가
SELECT to_date(tmp_date,'yyyymmdd')+1  from tmp_test;


○ 사용자정의 함수 작성(isdate.java)
import java.sql.*;

public class isdate{
    public static String chkDate(String strDate, String strDateFormat) throws SQLException {

        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;

        try{
            Class.forName("cubrid.jdbc.driver.CUBRIDDriver");
            conn = DriverManager.getConnection("jdbc:CUBRID:localhost:33000:demodb:::","","");
           
            String sql="SELECT to_date('" + strDate + "', '" + strDateFormat + "')" ;
           
            stmt = conn.createStatement();
            rs = stmt.executeQuery(sql);

            rs.close();
            stmt.close();
            conn.close();
            return "YES";

        } catch ( SQLException e ) {
            if ( conn != null ) conn.close();
            return "NO";
        } catch ( Exception e ) {
            return "NO";
        } finally {
            if ( conn != null ) conn.close();
        }
    }
}


○ 자바 컴파일 및 등록
 - 자바컴파일 : Javac isdate.java
 - CUBRID에 등록 : loadjava demodb isdate.class

 

○ 사용자정의 펑션 생성
create function isdate( strDate varchar, strDateFormat varchar) return string
as language java
name 'isdate.chkDate(java.lang.String, java.lang.String) return java.lang.String';

 

○ 날짜검사 테스트
call isdate('20120131', 'YYYYMMDD') ;
call isdate('20120132', 'YYYYMMDD') ;

 

select isdate(tmp_date,'YYYYMMDD'),   decode(isdate(tmp_date,'YYYYMMDD'), 'YES', tmp_date, '') as err_chk,tmp_date 
from tmp_test ;


  1. 9.2 버전에서 복제 재구축(ha_make_slavedb.sh) 스크립트를 사용하려면 수정해야 할 부분

    Date2013.10.24 Category운영관리 Bybrightest Views13352
    Read More
  2. CUBRID vs MySQL vs ORACLE SQL 타입별 비교

    Date2013.07.12 Category마이그레이션 By정만영 Views73836
    Read More
  3. 오류데이타검증 - 숫자 이외의 데이타 확인하는 방법

    Date2013.01.17 Category질의작성 By권호일 Views22151
    Read More
  4. join update 처리방법입니다.(연관성 있는 테이블을 조인하여 처리하는 UPDATE 구문)

    Date2012.11.30 Category질의작성 By권호일 Views21485
    Read More
  5. MySQL+XE를 CUBRID+XE로 운영하기 – mysqldump파일과 CMT사용

    Date2012.11.13 Category마이그레이션 Bycubebridge Views24426
    Read More
  6. CUBRID와 CUBRID Web Manager설치, 그리고 XE의설치 및 연동까지

    Date2012.11.13 CategoryCUBRID 매니저 Bycubebridge Views21253
    Read More
  7. CUBRID-PHP-Driver 연동가이드

    Date2012.11.13 Category응용개발 Bycubebridge Views18660
    Read More
  8. MySQL에서 CUBRID로 갈아탈 때 알아야 할 것

    Date2012.11.13 Category마이그레이션 Bycubebridge Views24315
    Read More
  9. 오라클 to CUBRID로 마이그레이션 수행 시 주의사항

    Date2012.11.12 Category응용개발 Bycubebridge Views18288
    Read More
  10. 오라클의 order by 시 first와 last 대체 사용법

    Date2012.11.12 Category마이그레이션 Bycubebridge Views22145
    Read More
  11. CUBRID에서의 BLOB/CLOB 사용시 백업 및 복구에 대한 주의 점

    Date2012.09.18 Category운영관리 Bycubebridge Views34367
    Read More
  12. 전자정부 표준프레임워크 CUBRID 사용 방법 문의 참조

    Date2012.09.17 Category기타 Bycubebridge Views22096
    Read More
  13. Windows 서버에서 [장치에 쓰기 캐싱 사용] 설정/해제에 따른 성능 차이

    Date2012.06.30 Category운영관리 By이용미 Views21524
    Read More
  14. 데이터 입력 중 디스크 공간 부족 오류가 발생하였을 때, 복구 방법

    Date2012.06.30 Category운영관리 By이용미 Views15437
    Read More
  15. 게시판 응용 중 조회수로 정렬하는 경우 인덱스 생성 방법

    Date2012.06.23 Category질의작성 By손승일 Views14802
    Read More
  16. 문자(char, varchar)로 설계한 날짜데이타 검증하기

    Date2012.04.27 Category질의작성 By권호일 Views18909
    Read More
  17. CUBRIDManager의 접속 정보 이관

    Date2012.04.14 CategoryCUBRID 매니저 Bycubebridge Views13777
    Read More
  18. CUBRID Migration Tookit 8.4.1

    Date2012.04.14 Category마이그레이션 Bycubebridge Views12408
    Read More
  19. CUBRID 에서의 사용자 권한관리 방법

    Date2012.04.14 Category운영관리 Bycubebridge Views25445
    Read More
  20. 데이터베이스 마이그레이션(unloaddb & loaddb) 의 효과적인 수행방법

    Date2012.04.14 Category마이그레이션 Bycubebridge Views26075
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15

Contact Cubrid

영업문의 070-4077-2112 / 기술문의 070-4077-2148 / 대표전화 070-4077-2110 / Email. contact_at_cubrid.com
Contact Sales