哦,只有在閱讀其他的答案後,我意識到這是什麼問題是什麼。我決定也保留我的原始答案,因爲關於if語句中的字符表達的觀點仍然正確。
其他答案是正確的,建立一個基於字符串評估與動態PL/SQL邏輯通常不是一個好主意。他們也提出正確的解決方案,但恕我直言更好的方法存在。
通常當我在PL/SQL中有多個條件時,我給條件一個名字。請參閱下面的示例說明該技術。這些名稱使得代碼自我記錄,並且在代碼可讀性方面有了巨大的提高,因爲現在的條件通常是人類語言。
declare
v_volume number := 0;
v_weight number := 1;
v_weight_limit constant number := 10;
v_volume_limit constant number := 10;
v_has_volume constant boolean := v_volume > 0;
v_exceed_weight_limit constant boolean := v_weight > v_weight_limit;
v_exceed_volume_limit constant boolean := v_volume > v_volume_limit;
begin
-- no guarantee the logic is the same than in question
-- but just illustrates the coding style
if v_has_volume
and v_exceed_weight_limit
and v_exceed_volume_limit
then
null; -- something
else
null; -- something else
end if;
end;
/