我的样本表如下:
TASKMASTER
TASKKEY TASKCOLTYPE01 TASKCOLDATA01
001 1 DONE
002 2 2
003 3 3
TASKCOLTYPE值:1 =文字,2 =是/否,3 =高/中/低
我有一个案例陈述:
SELECT TASKCOLTYPE01, TASCOLDATA01, CASE TASKCOLTYPE01 = 2
THEN CASE TASKCOLDATA01 =1 THEN 'YES' ELSE 'NO
CASE TASKCOLTYPE02 =3
THEN CASE TASKCOLDATA01=1 THEN 'HIGH WHEN TASKCOLDATA01 =2 THEN 'MID' ELSE 'LOW END
ELSE (RETURN the value itself)
END FROM TASKMASTER;
我想在表格中显示数据col(' DONE'在此示例中)
答案 0 :(得分:1)
希望这有帮助。
drop table TASKMASTER;
Create table TASKMASTER (
TASKKEY VARCHAR2(3)
, TASKCOLTYPE01 varchar2(255)
, TASKCOLDATA01 varchar2(255)
);
insert all
into TASKMASTER (TASKKEY, TASKCOLTYPE01, taskcoldata01) values (001, 1, 'DONE')
into TASKMASTER (TASKKEY, TASKCOLTYPE01, taskcoldata01) values (002, 2, 2)
into TASKMASTER (TASKKEY, TASKCOLTYPE01, taskcoldata01) values (002, 2, 1)
into TASKMASTER (TASKKEY, TASKCOLTYPE01, taskcoldata01) values (003, 3, 1)
into TASKMASTER (TASKKEY, TASKCOLTYPE01, taskcoldata01) values (003, 3, 2)
into TASKMASTER (TASKKEY, TASKCOLTYPE01, taskcoldata01) values (003, 3, 3)
select * from dual;
SELECT TASKCOLTYPE01, TASKCOLTYPE01, TASKCOLDATA01,
CASE
when TASKCOLTYPE01 = 2
THEN (CASE when TASKCOLDATA01 =1 THEN 'YES' ELSE 'NO' end)
when TASKCOLTYPE01 = 3
THEN ( CASE when TASKCOLDATA01=1 THEN 'HIGH'
WHEN TASKCOLDATA01 =2 THEN 'MID'
ELSE 'LOW'
END)
ELSE ( Taskcoldata01)
END result
FROM TASKMASTER;
答案 1 :(得分:0)
答案是
ELSE TO_CHAR(USERTASK.TASKCOLDATA01)
它将返回表字段中的值。
希望有所帮助!