「Oralce入門」DECODE()で条件分岐する方法

書式
SELECT
DECODE(カラム名, 値1, 結果1, 値2, 結果2, 結果3)
FROM tablename;

使用例1

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
SELECT
DECODE(COL_TYPE, '1', TEST_ID '2', SAMPLE_ID, DEFAULT_ID)
FROM TESTR_TBL
SELECT DECODE(COL_TYPE, '1', TEST_ID '2', SAMPLE_ID, DEFAULT_ID) FROM TESTR_TBL
SELECT
 DECODE(COL_TYPE, '1', TEST_ID '2', SAMPLE_ID, DEFAULT_ID)
FROM TESTR_TBL

使用例2

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
SELECT
AGE,
DECODE(INFO_ID, NULL, '1111', COL_ID)
FROM TEST_TBL;
SELECT AGE, DECODE(INFO_ID, NULL, '1111', COL_ID) FROM TEST_TBL;
SELECT 
 AGE,
 DECODE(INFO_ID, NULL, '1111', COL_ID) 
FROM TEST_TBL;

 

Oracle

Posted by arkgame