Previous Next JavaScript must be enabled to correctly display this content

## Using a query to update data

You can form queries to UPDATE a row in an Oracle NoSQL Database table. The WHERE clause must specify an exact primary key as only single row updates are allowed.

For example, to update a field using the UPDATE statement:

    // store handle creation omitted.

    ...

    // Updates the age for User with id=2
    StatementResult result = store.executeSync("UPDATE Users SET age=20
    WHERE id=2");

To update multiple rows, you must first form a query to SELECT records. You then use the result of the SELECT query to update or insert data.

For example, to update a field using a result record from the SELECT statement:

    // store handle creation omitted.

    ...

    TableAPI tableAPI = store.getTableAPI();
    Table table = tableAPI.getTable("Users");

    StatementResult result = store.executeSync("SELECT * FROM Users WHERE
    (age > 13 and age < 17)");

    for( RecordValue record : result ) {

        // Update a field
        Row row = table.createRow(record);
        row.put("age", record.get("age").asInteger().get() + 1);
        tableAPI.put(row, null, null);
    }