Oracle 12c: Updating Rows in a Table using PLSQL Extensions

Updating Rows with Records

The PL/SQL extension to the SQL UPDATE statement lets you update one or more table rows with a record. The record must represent a row of the table.

Example updates the first three weeks of the table schedule (defined in Example) by putting the new values in a record and updating the first three rows of the table with that record.

Example: Updating Rows with Record

DECLARE
default_week schedule%ROWTYPE;

BEGIN
default_week.Mon := 'Day Off';
default_week.Tue := '0900-1800';
default_week.Wed := '0900-1800';
default_week.Thu := '0900-1800';
default_week.Fri := '0900-1800';
default_week.Sat := '0900-1800';
default_week.Sun := 'Day Off';

FOR i IN 1..3 LOOP
default_week.week := i;

UPDATE schedule SET ROW = default_week
WHERE week = i;

END LOOP;

END;
/


SELECT * FROM schedule;

Result:

WEEK MON TUE WED THU FRI SAT SUN
---- --------- --------- --------- --------- --------- --------- ---------
1 Day Off 0900-1800 0900-1800 0900-1800 0900-1800 0900-1800 Day Off
2 Day Off 0900-1800 0900-1800 0900-1800 0900-1800 0900-1800 Day Off
3 Day Off 0900-1800 0900-1800 0900-1800 0900-1800 0900-1800 Day Off
4 0800-1700 0800-1700 0800-1700 0800-1700 0800-1700 Day Off Day Off
5 0800-1700 0800-1700 0800-1700 0800-1700 0800-1700 Day Off Day Off

6 0800-1700 0800-1700 0800-1700 0800-1700 0800-1700 Day Off Day Off

Comments

Popular posts from this blog

Query to get FSG report details with row/column set

Sub Ledger Period Close Exception Report - R12

Sub Inventory Transfer API.