I. All PLSQL exceptions have the following basic features: Error Type: indicates whether the error is a ORA error or a PLS error code: a string of numbers indicating the error code error text: error message text, including error code 2, PLSQL will produce two types of errors: ORA error PLS error ORA error is usually a runtime error, which should be caused
1. All PL/SQL exceptions have the following basic features: Error Type: indicates whether the error is a ORA error or a PLS error code: a string of numbers indicating the error code error text: the error message text, including the error code 2 and PL/SQL, may produce two types of errors: ORA error PLS error ORA error is usually a runtime error, which should be caused
1. All PL/SQL exceptions have the following basic features:
Error Type: indicates whether the error is a ORA error or a PLS error.
Error code: a string of numbers indicating the error code
Error text: error message text, including the error code
Ii. PL/SQL will produce two types of errors:
ORA Error
PLS Error
A ora error is usually a running error and should be handled by a program.
PLS errors are usually compilation errors and should be handled before the program is executed.
--: Outputs 99 multiplication tables using PL/SQL statement Blocks
-- Dbms_output.put_line ()
Declare
V_ I number;
V_k number;
V_j number;
Begin
For v_ I in 1 .. 9 loop
V_j: = 1;
While v_j <= v_ I loop
V_k: = v_ I * v_j;
Dbms_output.put_line ('v _ J' | v_j | '*' | 'v _ I '| v_ I |' = '| 'v _ k' | v_k);
V_j: = v_j + 1;
End loop;
Dbms_output.put_line (chr (10 ));
End loop;
End;
--: Use Select ename into v_ename from emp where deptno = & no;
-- A multi-line value exception (TOO_MANY_ROWS) occurs. Use the exception to print the error code and error information. Note that others is used to final.
Declare
V_ename emp. ename % type;
Begin
Select ename into v_ename from emp where deptno = & no;
Dbms_output.put_line ('v _ ename: '| v_ename );
-- If v_ename = 'chen'
-- Then dbms_output.put_line ('v _ ename: '| v_ename );
-- Else
-- Dbms_output.put_line ('too _ many_rows: '| sqlerrm );
-- End if;
Exception
When TOO_MANY_ROWS then
Dbms_output.put_line ('multi-value exception' | sqlerrm );
When others then
Dbms_output.put_line ('other exception ');
End;
--: Defines the row type of an emp table by using the employee ID % rowtype, and outputs the employee ID, name, salary, and department number.
-- Handle the exception that no data is found (no_data_found)
Declare
V_emp emp % rowtype;
Begin
Select * into v_emp from emp where empno = & employee ID;
Dbms_output.put_line ('v _ empno: '| v_emp.empno | 'v _ empname:' | v_emp.ename | 'v _ empsal '| v_emp.sal |' v _ empdeptno: '| v_emp.deptno );
Exception
When no_data_found then
Dbms_output.put_line ('exception: No data found '| sqlerrm );
When others then
Dbms_output.put_line ('other exception ');
End;