decode(col_name,1,值1,2,值2,3,值3,null)==> if col_name=1 then dbms_output.put_line(值1); elsif col_name=2 then dbms_output.put_line(值2); elsif col_name=3 then dbms_output.put_line(值3); else dbms_output.put_line(null); end if;
decode(col_name,1,值1,2,值2,3,值3,null)==> if col_name=1 then dbms_output.put_line(值1); elsif col_name=2 then dbms_output.put_line(值2); elsif col_name=3 then dbms_output.put_line(值3); else dbms_output.put_line(null); end if;
那不是和iif一样?用sql语句这么写的: case statement when case1 then statemwnt…………end case是这个意思吗?
类似于SQL Server中的case when功能
select case when tab_1.a = tab_1.b then 'error' when tab_1.c = tab_1.d then 'ok' from tab_1 大虾们以上语句在Oracle中如何实现....
select case when tab_1.a = tab_1.b then 'error' when tab_1.c = tab_1.d then 'ok' else 'none' end case from tab_1 大虾们以上语句在Oracle中如何实现....
sql语句不行吗? 在Sql语句中可以用if吗?
decode 跟if一样 example : select decode(item_name ,'A',1,'B',2,'C',3,4) FROM TABLE_NAME; 也就是 if item_name = 'A' THEN item_name := 1; elsif item_name = 'B' THEN item_name := 2; elsif item_name = 'C' THEN item_name := 3; else item_name := 4; end if;
if col_name=1 then
dbms_output.put_line(值1);
elsif col_name=2 then
dbms_output.put_line(值2);
elsif col_name=3 then
dbms_output.put_line(值3);
else
dbms_output.put_line(null);
end if;
if col_name=1 then
dbms_output.put_line(值1);
elsif col_name=2 then
dbms_output.put_line(值2);
elsif col_name=3 then
dbms_output.put_line(值3);
else
dbms_output.put_line(null);
end if;
case statement when case1 then statemwnt…………end case是这个意思吗?
when tab_1.c = tab_1.d then 'ok'
from tab_1
大虾们以上语句在Oracle中如何实现....
when tab_1.c = tab_1.d then 'ok'
else 'none'
end case
from tab_1
大虾们以上语句在Oracle中如何实现....
在Sql语句中可以用if吗?
example :
select decode(item_name ,'A',1,'B',2,'C',3,4) FROM TABLE_NAME;
也就是
if item_name = 'A' THEN
item_name := 1;
elsif item_name = 'B' THEN
item_name := 2;
elsif item_name = 'C' THEN
item_name := 3;
else
item_name := 4;
end if;
而iif好像只有两个分支
iif(逻辑表达式A,value1,value2)
如果逻辑表达式A值为True,那么返回value1,否则返回value2Decode(表达式A,表达式1,value1,表达式2,value2...)
如果表达式1等于表达式A,返回value1,否则
如果表达式2等于表达式A,返回value2,否则其实上面几位大虾们说得都是对的!