--cursor cursor_name is select_statement--For loop cursors--(1) Defining Cursors--(2) Defining a cursor variable--(3) using the For loop to use this cursorDeclare --type definition cursorC_job is SelectEmpno,ename,job,sal fromEMPwhereJob='MANAGER'; --defines a cursor variable v_cinfo c_emp%rowtype, which is a row of data types in the cursor c_empC_row C_job%RowType;begin forC_rowinchC_job Loop dbms_output.put_line (C_row.empno||'-'||C_row.ename||'-'||C_row.job||'-'||c_row.sal); EndLoop;End;
Examples of practical work:
Declarev_temp Number;--Defining Variablesv_part_idVARCHAR2( -);--Defining Variables cursorC_job--Defining Cursors is SELECTDept_id,dept_code,dept_type fromPub_depart_infoORDER bydept_id; C_row C_job%RowType--defines the variable c_row, which is a row of data in the cursor c_jobbegin OpenC_job;--Open CursorLoop--Start Loop FetchC_job intoC_row;--reading a row of data Exit whenC_job%NotFound--exit when data is empty (that is, when the loop is complete) ifC_row. Dept_code is NULL Then --the method of calling the field data is C_row. Dept_code, where Dept_code is the column name in the database IFC_row. Dept_type= 1 Thenv_temp:= 0; Select Max(Dept_code)+1 intov_part_id fromPub_depart_infoWHEREDept_type= '1'; UpdatePub_depart_infoSetDept_code=v_part_idwheredept_id=C_row. dept_id; ELSEv_temp:=V_temp+ 1; IFV_temp< Ten Then UpdatePub_depart_infoSetDept_code=(v_part_id|| '0000' ||v_temp)wheredept_id=C_row. dept_id; ELSE UpdatePub_depart_infoSetDept_code=(v_part_id|| ' the' ||v_temp)wheredept_id=C_row. dept_id; END IF; END IF; End if; EndLoop--End Loop CloseC_job;--Close CursorsEnd;
Examples of Oracle Tour signs