Declare cursor cur_login are select user_id, login, login_time from User_login; type User_id_type is table of User_login.user_id%type; type login_type is table of User_login.login%type; type Login_time_type is table of User_login.login_time%type; id_tab User_id_type; login_tab login_type; login_time_tab Login_time_type; v_limit pls_integer: = 5000; Begin open Cur_login; loop fetch cur_login bulk collect into Id_tab, login_tab, Login_time_tab limit V_li Mit exit when id_tab.count = 0; forall i in Id_tab.first. Id_tab.last insert into User_login_bak values (Id_tab (i ), Login_tab (i), Login_time_tab (i)); commit; end Loop; close Cur_login; End /DECLARE cursor cur is select USer_id, LOGIN, login_time from User_login; v_user_id dbms_sql. number_table; ---is not recorded, it is set v_login dbms_sql. number_table; ---is not a record, is set v_login_time dbms_sql.date_table; ------is not recorded, is set begin open cur; loop fetch cur bulk collect into v_user_id, V_login, v_login_time limit 5000; ----Get 5000 rows at a time; forall I in 1. V_user_id.count insert into User_login_bak values (V_us ER_ID (i), V_login (i), v_login_time (i)); ----Here I mean 1..5000 commit; exit when cur%notfound or cur%notfound is null; end Loop; close cur; commit; End Declare cursor cur_user_login is select user_id, login, login_time from User_login; type Cur_type is table of the Cur_user_login%rowtype index by Pls_integer; --- index by Binary_integer is an array of fixed syntax cur_tab cur_type; Begin open Cur_user_logIn; loop fetch cur_user_login bulk collect into Cur_tab limit 5000; ----Get 5000 rows at a time; forall I in 1. Cur_tab.count insert into User_login_bak (user_id, LOGIN, login_time) values (cur_ tab (i). USER_ID, Cur_tab (i). LOGIN, Cur_tab (i). Login_time); commit; Exit when Cur_user_login%notfound or cur_user_login%notfound is null; End Loop; close Cur_user_login; commit; End
In addition to the volume cursors, there are dynamic cursors: What is a dynamic cursor? The SQL statement is not known at the time of execution, and is not known from the outset: REF cursor belongs to the dynamic cursor (this query is not known until run time). Let's look at an example:---This is bulk delete data create or replace procedure Delbigtab (P_tablename in Varchar2, P_condition in VARCHAR2) as type mycur is REF CURSOR; V_cur mycur; V_cur_sql VARCHAR2 (3000); Type V_rowid is table