NULL対応式の記述
スクリプトを記述する場合は、フィールド値がnullになる可能性があることに注意してください。 nvl()のnull値関数を使用すると、使用するスクリプト式の一部としてnullのかわりに使用する値を簡単に定義できます。
次の例を考えてみます。
// Assign a date three days after the PostedDate
// Use the current date instead of the PostedDate if the
// PostedDate is null
def targetDate = nvl(PostedDate,now()) + 3
// Increase an employee's custom Salary field value by 10 percent
// Use zero if current Salary is null
Salary = nvl(Salary,0) * 1.1
ヒント:
nvl()
関数に渡す両方の式のデータ型が同じである必要があります。そうしないと、コードを保存するときにタイプ・チェックの警告が表示されます。 たとえば、Salary
が数値フィールドの場合、最初の式は数値で、2番目の式は文字列であるため、nvl(Salary,’<No Salary>’)
のような式の使用は正しくありません。