In addition to static SQL discussed in this chapter, PL/SQL also supports dynamic SQL, which enables you to execute SQL data definition, data control, and session control statements dynamically.See Chapter 7, "Performing SQL Operations with Native Dynamic SQL".DECLARE MSG VARCHAR2(500); SMS_TYPE VARCHAR(20); DDACDATE DATE; CUR SMSTYPE%ROWTYPE; CURSOR C_SMS IS SELECT SMS_ID, COL_01, COL_02, COL_03, COL_04 FROM SMS;-- FOR UPDATE OF SMS_CONTENT NOWAIT; REC_SMS C_SMS%ROWTYPE; BEGIN SELECT * INTO CUR FROM SMSTYPE WHERE SMSTYPE_NAME = 'RENEWAL'; MSG := CUR. PUT_LINE(MSG); END LOOP; CLOSE C_SMS; END; My problem is, the output is being repeated with the same values for the duration of the loop i.e. I have commented out the update statement because I am getting the same values repeated for all records in the target table.SMSTYPE_MSG; OPEN C_SMS; LOOP FETCH C_SMS INTO REC_SMS; EXIT WHEN C_SMS%NOTFOUND; -- cursor attribute to exit when no rows found to fetch. How can I ensure that each output value is different for the current record in the cursor? if at first iteration MSG is I think the issue is that you are overwritting your tokens (like |INSURED|, etc) in the MSG string during the firt iteration.SMSTYPE_MSG for each iteration of the loop or you need to use a temp variable.
When the Fetch clause is used with a cursor having a FOR UPDATE clause, the PL/SQL unit fails when we try to open the cursor with an ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc. The error description shows that the internal mechanism for the Fetch clause uses either a DISTINCT or a GROUP BY clause which is not permitted alongside the FOR UPDATE clause.This clause can also be extended to lock only the intended table in the SELECT query containing more than one table in joins using the FOR UPDATE OF clause.This clause becomes meaningless if we use a single table SELECT clause as the minimum Oracle has provided us with the WHERE CURRENT OF clause for both DELETE and UPDATE statements inside a cursor’s range to make changes to the last fetched row(s) from the cursor with an ease.Once we open a cursor having a FOR UPDATE clause, all the rows returned by the SELECT statement are locked for our changes until a commit or a rollback is placed to release the lock.After a TCL operation is performed, the cursor pointer gets reset and the cursor will be no longer accessible, thus results in an error when fetched further as shown below. ), how I might cluster rows together that are subject to updates, and what I might do if I just get too many updates to handle. The fastest way to update every row in the table is to rebuild the table from scratch. Case 2 is common in Data Warehouses and overnight batch jobs.