SQL のコンテキストでは、EGL replace 文は、SQL レコード変数からリレーショナル・データベースの行に、改訂された情報を戻します。
この文は、生成済みコードにおいて、SQL UPDATE 文を作成します。 EGL では、SQL レコード変数内の情報やプロパティーに基づいてこの文を暗黙的に作成できます。 また、#sql ディレクティブ (sql ディレクティブを参照) を使用して、replace 文に SQL コードを明示的に組み込むことができます。

UPDATE tableName
SET column01 = :myField01,
column02 = :myField02,
...
columnNN = :myFieldNN
WHERE CURRENT OF cursor
以下は、replace ステートメントを含んだコードです。 このコードは、完全な SQL プログラム (サンプル EGL SQL プログラムに記載) から引用したものです。
try
get dept forupdate;
dept.description = "Test Engineers";
replace dept;
commit();
onException(sqlEx SQLException)
sqlFailure();
end
次の例は、複数行に対する replace ステートメントを示しています。
employees Employee[0]{rowsetsize=10};
Open resultset1 forUpdate with #sql{
select eID, uName, PASSWORD, fName, lName, office, sex, EMail
from EMPLOYEETEST
} for employees;
Get Next employees;
//this updates the second row in the row set with current contents
employees[2].uName = “test”;
Replace employees[2];
// this updates the second row in the row set with explicit variable
newName CHAR(20) = “test1”;
Replace employees[2]
#with SQL{ update EMPLOYEETEST
set uName = :newName };
// the index can be a variable
i int = 2;
Replace employees[i];
//this updates all rows in the row set with uName = "test"
//Explicit SQL must be used, otherwise there should be a
//validation error.
uName CHAR(10) = “test”;
Replace employees
#with SQL{ update EMPLOYEETEST
set uName = :uName };
| プラットフォーム | 問題 |
|---|---|
| COBOL 生成 | COBOL のパフォーマンスを最適にするために、replace ステートメントには常に from resultSet 文節を組み込んでください。 |
| SQL Server | 複数行の delete last と get last を同時に使用することはできません。両方のステートメントを一度に実行すると、結果セットは閉じられます。 |
| DB2® for i5/OS™ | ジャーナル処理を使用可能にするか、接続ストリングに transation isolation=none を追加する必要があります。 |