在 Java 中,沒有內置的 nvl 函數,但是你可以使用三元運算符(? :)或者自定義一個方法來實現類似的功能
public class NVLExample {
public static void main(String[] args) {
String value = null;
String defaultValue = "default";
String result = (value != null) ? value : defaultValue;
System.out.println("Result: " + result); // 輸出 "Result: default"
}
}
nvl 方法:public class NVLExample {
public static void main(String[] args) {
String value = null;
String defaultValue = "default";
String result = nvl(value, defaultValue);
System.out.println("Result: " + result); // 輸出 "Result: default"
}
public static <T> T nvl(T value, T defaultValue) {
return (value != null) ? value : defaultValue;
}
}
在這兩個示例中,我們檢查 value 是否為 null。如果不是 null,則返回 value;否則返回 defaultValue。這就是 nvl 函數的基本功能。你可以根據需要修改這些示例,以適應你的具體需求。