我正在考虑将 if 块转换为我的 pl/sql 函数中的解码。由于我们不能直接在 pl/sql 中使用decode,因此计划是使用“selectdecode()tovariablefromdual”。现有的 if 块如下:
if var1 = 'a' then
var2 := 'x';
elseif var1 = 'b' then
var2 := 'y';
else
var2 := 'z';
end if;
Run Code Online (Sandbox Code Playgroud)
替换解码可以是:
select decode(var1,'a','x','b','y','z') into var2 from dual;
Run Code Online (Sandbox Code Playgroud)
通过解码可以显着减少代码行(对于类似的较大块),但这是更好的方法吗?