Data Modification

Modify data using the MLE JavaScript SQL driver.

In addition to selecting data, it is possible to insert, update, delete, and merge data using the MLE JavaScript SQL driver. The same general workflow can be applied to these operations as you would use when selecting data.

Example 7-7 Updating a Row Using the MLE JavaScript SQL Driver

CREATE OR REPLACE MLE MODULE row_update_mod LANGUAGE JAVASCRIPT AS 
import oracledb from "mle-js-oracledb"; 
export function updateCommissionExampleEmpID145() { 
    const conn = oracledb.defaultConnection(); 
    const result = conn.execute( 
        `UPDATE employees 
         SET commission_pct = commission_pct * 1.1  
         WHERE employee_id = 145`
    ); 
    return result.rowsAffected; 
} 
/ 

The result object's rowsAffected property can be interrogated to determine how many rows have been affected by the update. The JavaScript function updateCommissionExampleEmpID145() returns the number of rows affected to the caller. In this instance, the function will return 1.

An alternative method to update data is to use the connection.executeMany() method. This function works best when used with bind variables.