Number of lines deleted from the output bound to the variable
Execute in PLSQL command window. By default, the value of the bound variable is printed.
SQL> variable rows_deleted number
SQL> declare
2 v_id number: = 11;
4 begin
5 delete from building where id = v_id;
6: Rows_deleted: = SQL % rowcount;
7 end;
8/
PL/SQL procedure successfully completed
Rows_deleted
---------
0
Normal variables cannot be output by printing
SQL> variable rows_deleted number
SQL> declare
2 v_id number: = 11;
4 begin
5 delete from building where id = v_id;
6Rows_deleted: = SQL % rowcount;
7 end;
8/
PL/SQL procedure successfully completed
Only prompts that the process is executed. to output this variable, you must output it through the dbms_output process.
Run in sqlplus
SQL> variable rows_deleted number
SQL> declare
2 v_id number: = 11;
3 begin
4 Delete from building where id = v_id;
5: rows_deleted: = SQL % rowcount;
6 end;
7/
The PL/SQL process is successfully completed.
SQL> Print rows_deleted
Rows_deleted
------------
0
The following statement is also executed in the Command window of PLSQL
SQL> variable rows_deleted number
SQL> declare
2 type v_id_table_type is table of Building. ID % type;
3 v_id_table v_id_table_type;
4 begin
5 select ID bulk collect into v_id_table from building where rownum <= 10;
6: rows_deleted: = SQL % rowcount;
7 end;
8/
PL/SQL procedure successfully completed
Rows_deleted
---------
10