[오라클]Data Type - DECODE 함수와 ORA-01722
DECODE()함수의 Return 값
Return값 = DECODE(expr, search, result [, search, result ]... [, default ]) <pre> </pre>
- DECODE() 함수의 Return값은 첫번째 result(3번째 인수)의 Datatype에 따라 달라진다.
- 첫번째 result(3번째 인수)가 null 이라면 Return값의 Datatype은 String이다.
- 첫번째 result(3번째 인수)와 나머지 result나 defaut의 Datatype이 다르면
"ORA-01722: 수치가 부적합합니다." 에러가 발생한다.
------------------------------------------------------------------------------------------
Oracle® Database SQL Reference
10g Release 2 (10.2)
Part Number B14200-02
[Purpose]
DECODE
comparesexpr
to eachsearch
value one by one.If
expr
is equal to asearch
, then Oracle Database returns the correspondingresult
.If no match is found, then Oracle returns
default
.If
default
is omitted, then Oracle returns null.
The arguments can be any of the numeric types (
NUMBER
,BINARY_FLOAT
, orBINARY_DOUBLE
)or character types.
- If
expr
andsearch
are character data,then Oracle compares them using nonpadded comparison semantics.
expr
,search
, andresult
can be any of the datatypesCHAR
,VARCHAR2
,NCHAR
, orNVARCHAR2
.The string returned is of
VARCHAR2
datatype and is in the same character setas the first
result
parameter.- If the first
search-result
pair are numeric,then Oracle compares all
search-result
expressions and the firstexpr
to determinethe argument with the highest numeric precedence, implicitly converts the remaining
arguments to that datatype, and returns that datatype.
The
search
,result
, anddefault
values can be derived from expressions.Oracle Database uses short-circuit evaluation.
That is, the database evaluates each
search
value only before comparing it toexpr
,rather than evaluating all
search
values before comparing any of them withexpr
.Consequently, Oracle never evaluates a
search
if a previoussearch
is equal toexpr
.Oracle automatically converts
expr
and eachsearch
value to the datatypeof the first
search
value before comparing.
Oracle automatically converts the return value to the same datatype as the first
result
.If the first
result
has the datatypeCHAR
or if the firstresult
is null,then Oracle converts the return value to the datatype
VARCHAR2
.
In a
DECODE
function, Oracle considers two nulls to be equivalent.If
expr
is null, then Oracle returns theresult
of the firstsearch
that is also null.
The maximum number of components in the
DECODE
function, includingexpr
,
searches
,results
, anddefault
, is 255.
'01.오라클 > 007.DB Knowledge Base' 카테고리의 다른 글
[오라클]V$session Command 컬럼의 코드표 (0) | 2012.12.19 |
---|---|
[오라클]exp/imp 단순 이관 방법 및 순서 (0) | 2012.12.19 |
[오라클]PK컬럼 순서와 데이터베이스 성능 (0) | 2012.12.19 |
[오라클]설치 시 커널 매개변수 설정 (0) | 2012.12.19 |
[오라클]INDEX 생성 가이드라인 (0) | 2012.12.19 |