Oacle 데이터 암시 적 변환 규칙

Oacle 에서 서로 다른 데이터 형식 간 에 연결 되 어 있 으 면 데 이 터 를 명시 적 으로 변환 하지 않 으 면 다음 과 같은 규칙 에 따라 데 이 터 를 암시 적 으로 변환 합 니 다. 이런 전환 으로 인해 가장 흔히 볼 수 있 는 문 제 는 색인 이 효력 을 잃 는 것 입 니 다. 따라서 이러한 전환 을 최대한 피하 고 시스템 데이터 베이스 설정 단계 에서 점검 해 야 합 니 다.변환 규칙 은 공식 문서 SQL 참조 참조 /Datatype Comparison Rules 에서 설명 한 내용:
The following rules govern the direction in which Oracle makes implicit datatype conversions:
1) During INSERT and UPDATE operations, Oracle converts the value to the datatype of the affected column.      INSERT 와 UPDATE 작업 에 대해 Oacle 은 삽입 값 이나 업데이트 값 을 필드 의 데이터 형식 으로 변환 합 니 다.만약 id 열의 데이터 형식 이 number update t set id = '1' 이 라면; - >update t set id = tonumber('1'); insert into t(id) values('1') -> insert into t values(to_number('1'));
2) During SELECT FROM operations, Oracle converts the data from the column to the type of the target variable.     SELECT 구문 에 대해 Oacle 은 필드 의 데이터 형식 을 변수의 데이터 형식 으로 암시 적 으로 변환 합 니 다.예 를 들 어 id 열의 데이터 형식 이 varchar 2 select * from t where id = 1 이 라 고 가정 하면; - >select * from t where to_number(id)=1; 그러나 id 열의 데이터 형식 이 number 라면 select * from t where id = '1'; - >select * from t where id=to_number('1');(다음 글 참조)
3) When comparing a character value with a NUMBER value, Oracle converts the character data to NUMBER.     문자 형 과 수치 형의 값 을 비교 할 때 Oacle 은 문자 형의 값 을 암시 적 으로 수치 형 으로 변환 합 니 다.예 를 들 어 id 열의 데이터 형식 이 number select * from t where id = '1' 이 라 고 가정 하면 - >select * from t where id=to_number('1');
4) When comparing a character value with a DATE value, Oracle converts the character data to DATE.     문자 형 과 날짜 형의 데 이 터 를 비교 할 때 Oacle 은 문자 형 을 날짜 형 으로 변환 합 니 다.가령 createdate 는 문자 형, select * from t where createdate>sysdate; -> select * from t where to_date(create_date)>sysdate;(이 때 session 의 nls date format 는 문자열 형식 과 일치 해 야 합 니 다) createdate 는 date 형, select * from t where createdate>'2006-11-11 11:11:11'; -> select * from t where create_date>to_date('2006-11-11 11:11:11'); (이 때 session 의 nls date format 는 문자열 형식 과 일치 해 야 합 니 다)
5) When you use a SQL function or operator with an argument of a datatype other than the one it accepts, Oracle converts the argument to the accepted datatype.      함수 나 프로 세 스 등 을 호출 할 때 입력 매개 변수의 데이터 형식 과 함수 또는 프로 세 스 가 정의 하 는 매개 변수 데이터 형식 이 계속 되 지 않 으 면 Oacle 은 입력 매개 변수의 데이터 형식 을 함수 나 프로 세 스 가 정의 하 는 데이터 형식 으로 변환 합 니 다.가설 과정 은 다음 과 같이 p (p 1 number) exec p ('1') 를 정의 합 니 다. - >exec p(to_number('1'));
6) When making assignments, Oracle converts the value on the right side of the equal sign (=) to the datatype of the target of the assignment on the left side.     값 을 할당 할 때 Oacle 은 등호 오른쪽 데이터 형식 을 왼쪽 데이터 형식 으로 변환 합 니 다.var a number a: = '1'; - >a:=to_number('1'); 7) During concatenation operations, Oracle converts from noncharacter datatypes to CHAR or NCHAR.     연결 연산 자 (| |) 를 사용 할 때 Oacle 은 비 문자 형식의 데 이 터 를 문자 형식 으로 변환 합 니 다.select 1||'2' from dual; -> select to_char(1)||'2' from dual; 8) During arithmetic operations on and comparisons between character and noncharacter datatypes, Oracle converts from any character datatype to a number, date, or rowid, as appropriate. In arithmetic operations between CHAR/VARCHAR2 and NCHAR/NVARCHAR2, Oracle converts to a number.     문자 형식의 데이터 와 비 문자 형식의 데이터 (예 를 들 어 number, date, rowid 등) 가 산술 연산 을 하면 Oacle 은 문자 형식의 데 이 터 를 적당 한 데이터 형식 으로 변환 합 니 다. 이 데이터 형식 들 은 number, date, rowid 등 일 수 있 습 니 다.CHAR / VARCHAR 2 와 NCHAR / NBARCHAR 2 사이 에 산술 연산 을 하면 Oacle 은 이들 을 모두 number 형식의 데이터 로 변환 하여 비교 할 것 이다.9) Comparisons between CHAR/VARCHAR2 and NCHAR/NVARCHAR2 types may entail different character sets. The default direction of conversion in such cases is from the database character set to the national character set.
    CHAR / VARCHAR 2 와 NCHAR / NBARCHAR 2 를 비교 할 때 두 문자 집합 이 다 르 면 기본 변환 방식 은 데이터 인 코딩 을 데이터베이스 문자 집합 에서 국가 문자 집합 으로 변환 하 는 것 입 니 다.
10)Conversions between character values or NUMBER values and floating-point number values can be inexact, because the character types and NUMBER use decimal precision to represent the numeric value, and the floating-point numbers use binary precision.
   문자 값 이나 수치 와 부동 소수점 값 변환 이 정확 하지 않 을 수 있 습 니 다. 문자 와 수치 유형 은 10 진법 으로 숫자 를 표시 하고 부동 소수점 값 은 2 진법 을 사용 하기 때 문 입 니 다.
간단 한 요약: 비교 할 때 보통 문자 형 을 수치 형 으로 바 꾸 고 문자 형 을 날짜 형 산술 연산 으로 바 꿀 때 보통 문자 형 을 수치 형 으로 바 꾸 고 문자 형 을 날짜 형 으로 연결 할 때 (| |), 보통 수치 형 을 문자 형 으로 바 꾸 고 날짜 형 을 문자 형 할당, 호출 함수 로 바 꿀 때 정 의 된 변수 유형 을 기준 으로 한다.

좋은 웹페이지 즐겨찾기