Plsql loop application begin -- two single quotes replace one double quotation mark execute immediate 'create table T (nnn varchar2 (20) default ''aaa') '; end; drop table T; in PLSQL, the judge branch and loop eg: Get the salary of 7369 of the person, if <1200, 'low' is output. If <2000, "middle" is output; otherwise, 'high' 7839 declare v_sal emp is output. sal % type; begin select sal into v_sal from emp where empno = 7369; if (v_sal <1200) then dbms_output.put_line ('low'); elsif (v_sal <2000) then dbms_output.put_line ('midddle'); else dbms_output.put_line ('high'); end if; end; loop :( do while () declare I binary_integer: = 1; begin loop dbms_output.put_line (I); I: = I + 1; exit when (I> = 11); end loop; -- equivalent to do while () loop end; while () loop declare j binary_integer: = 1; begin while j <11 loop dbms_output.put_line (j); j: = j + 1; end loop; end; () loop begin for k in 1 .. 10 loop dbms_output.put_line (k); end loop; for k in reverse 1 .. 10 loop dbms_output.put_line (k); end loop; end; error handling: too many lines of Exception: declare v_temp number (4); begin select empno into v_temp from emp where deptno = 10; exception when too_many_rows then dbms_output.put_line ('Too many records'); when others then dbms_output.put_line ('error'); end; Data exception not found: declare v_temp number (3 ); begin select empno into v_temp from emp where empno = 2222; exception when no_data_found then dbms_output.put_line ('no date'); end; dba often records errors: create table errorlog (id number primary key, errcode number, errmsg varchar2 (1024), errdate date); create a sequence because the error is auto-incrementing, save the data create sequence seq_errorlog_id start with 1 increment by 1; declare v_deptno dept. deptno % type: = 10; v_errcode number; v_errmsg varchar2 (1024); begin delete from dept where deptno = v_deptno; commit; exception when others then rollback; v_errcode: = SQLCODE; v_errmsg: = SQLERRM; insert into errorlog values (seq_errorlog_id.nextval, v_errcode, v_errmsg, sysdate); commit; end; select * from errorlog; specific error time select to_char (errdate, 'yyyy-MM-DD HH24: MI: ss') from errorlog; declare cursor c is select * from emp2 for update; -- v_temp c % rowtype; begin for v_temp in c loop if (v_temp.sal <2000) then update emp2 set sal = sal * 2 where current of c; elsif (v_temp.sal = 5000) then delete from emp2 where current of c; end if; end loop; commit; end;