1,while Cycle
DeclareV_tnamevarchar2( -); cursorC_tname is SelectA.table_name fromUser_tables AwhereA.tablespace_name= 'Vtmdata';begin OpenC_tname; FetchC_tname intoV_tname; whileC_tname%found Loop dbms_output.put_line (v_tname); FetchC_tname intoV_tname; --You must fetch it here or you will always take the first one that causes a dead loop .EndLoop; CloseC_tname; --To manually close the cursor otherwise cannot be used again End;
2,for Cycle
Declare cursorC_tname is SelectA.table_name fromUser_tables AwhereA.tablespace_name= 'Vtmdata';begin forTnameinchC_tname Loop Dbms_output.put_line (tname.table_name); --Using the "." operator to go to the corresponding column EndLoop--Automatically closes the cursor after the loop is completed without manual closingException whenOthers ThenDbms_output.put_line (Sqlcode); Dbms_output.put_line (SQLERRM);End;
Oracle Traversal Cursors