In Oracle SQL PLUS, after the update, delete, or select DML operations, the number of rows updated, deleted, or retrieved is displayed. In the JDBC operation, the returned value also indicates how many rows are affected. But how can we obtain this data in PL/SQL.
In PL/SQL, when you perform a search, you can open a cursor by yourself or not, but when you do not open the cursor, the system uses an implicit cursor in the background to achieve the same effect. Therefore, we can use some properties of the implicit cursor to obtain the execution result of the DML statement.
These attributes are obtained by using the SQL % field. Generally, three types of attributes are used: SQL % FOUND and SQL % NOTFOUND, the return values of these two types are boolean values such as true and false. The third return value is SQL % ROWCOUNT, which returns the number of data pieces in the previous operation.
The returned values of SQL % FOUND are as follows:
TRUE: INSERT
. TRUE: DELETE and UPDATE. At least one row is deleted or updated.
. TRUE: select into returns at least one row.
When SQL % FOUND is TRUE, SQL % NOTFOUND is FALSE.
In addition, I heard that sqlca. sqlerrd [2] can also return the number of update items. I didn't verify it. I don't know if I can.