달력

122024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

[함수]DECODE

DB 2008. 11. 6. 17:54

http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/index.htm

DECODE

Syntax

decode::=

Text description of functions157.gif follows 
Text description of decode


Purpose

DECODE compares expr to each search value one by one. If expr is equal to a search, then Oracle returns the corresponding result. If no match is found, then Oracle returns default. If default is omitted, then Oracle returns null.

If expr and search contain character data, then Oracle compares them using nonpadded comparison semantics. exprsearch, and result can be any of the datatypes CHARVARCHAR2NCHAR, or NVARCHAR2. The string returned is of VARCHAR2 datatype and is in the same character set as the first result parameter.

The searchresult, and default values can be derived from expressions. Oracle evaluates each search value only before comparing it to expr, rather than evaluating all search values before comparing any of them with expr. Consequently, Oracle never evaluates a search if a previous search is equal to expr.

Oracle automatically converts expr and each search value to the datatype of 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 datatype CHAR or if the first result 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 the result of the first search that is also null.

The maximum number of components in the DECODE function, including exprsearchesresults, and default, is 255.

See Also:

Examples

This example decodes the value warehouse_id. If warehouse_id is 1, then the function returns 'Southlake'; if warehouse_id is 2, then it returns 'San Francisco'; and so forth. If warehouse_id is not 1, 2, 3, or 4, then the function returns 'Non-domestic'.

SELECT product_id, DECODE (warehouse_id, 1, 'Southlake', 2, 'San Francisco', 3, 'New Jersey', 4, 'Seattle', 'Non-domestic') "Location of inventory" FROM inventories WHERE product_id < 1775;

'DB' 카테고리의 다른 글

SQLPlus 를 이용한 Query trace  (0) 2008.11.12
[함수]NVL, NVL2  (0) 2008.11.06
ORA-04030  (1) 2008.11.06
대용량DB에서 FK의 필요성 - sarang.net  (0) 2008.10.28
SQLPlus 사용법  (0) 2008.10.25
Posted by marryjane
|