Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
40
Добавлен:
16.04.2013
Размер:
4.96 Mб
Скачать

Handling PL/SQL Compile-Time Errors

ELSIF Discrim = 2 THEN

OPEN Cv FOR SELECT * FROM Dept_tab;

END IF;

END Open_cv;

END Emp_dept_data;

You can call the Open_cv procedure to open the cursor variable and point it to either a query on the Emp_tab table or the Dept_tab table. The following PL/SQL block shows how to fetch using the cursor variable, and then use the ROWTYPE_ MISMATCH predefined exception to handle either fetch:

DECLARE

Emp_rec Emp_tab%ROWTYPE;

Dept_rec Dept_tab%ROWTYPE;

Cv Emp_dept_data.CV_TYPE;

BEGIN

Emp_dept_data.open_cv(Cv, 1); -- Open Cv For Emp_tab Fetch Fetch cv INTO Dept_rec; -- but fetch into Dept_tab record

-- which raises ROWTYPE_MISMATCH DBMS_OUTPUT.PUT(Dept_rec.Deptno);

DBMS_OUTPUT.PUT_LINE(' ' || Dept_rec.Loc);

EXCEPTION

WHEN ROWTYPE_MISMATCH THEN BEGIN

DBMS_OUTPUT.PUT_LINE

('Row type mismatch, fetching Emp_tab data...'); FETCH Cv INTO Emp_rec; DBMS_OUTPUT.PUT(Emp_rec.Deptno); DBMS_OUTPUT.PUT_LINE(' ' || Emp_rec.Ename);

END;

Handling PL/SQL Compile-Time Errors

When you use SQL*Plus to submit PL/SQL code, and when the code contains errors, you receive notification that compilation errors have occurred, but there is no immediate indication of what the errors are. For example, if you submit a standalone (or stored) procedure PROC1 in the file proc1.sql as follows:

SQL> @proc1

Using Procedures and Packages 7-33

Handling PL/SQL Compile-Time Errors

And, if there are one or more errors in the code, then you receive a notice such as the following:

MGR-00072: Warning: Procedure proc1 created with compilation errors

In this case, use the SHOW ERRORS statement in SQL*Plus to get a list of the errors that were found. SHOW ERRORS with no argument lists the errors from the most recent compilation. You can qualify SHOW ERRORS using the name of a procedure, function, package, or package body:

SQL> SHOW ERRORS PROC1

SQL> SHOW ERRORS PROCEDURE PROC1

See Also: SQL*Plus User's Guide and Reference for complete information about the SHOW ERRORS statement

Note: Before issuing the SHOW ERRORS statement, use the SET LINESIZE statement to get long lines on output. The value 132 is usually a good choice. For example:

SET LINESIZE 132

Assume that you want to create a simple procedure that deletes records from the employee table using SQL*Plus:

CREATE OR REPLACE PROCEDURE Fire_emp(Emp_id NUMBER) AS BEGIN

DELETE FROM Emp_tab WHER Empno = Emp_id; END

/

Notice that the CREATE PROCEDURE statement has two errors: the DELETE statement has an error (the E is absent from WHERE), and the semicolon is missing after END.

After the CREATE PROCEDURE statement is entered and an error is returned, a SHOW ERRORS statement returns the following lines:

SHOW ERRORS;

ERRORS FOR PROCEDURE Fire_emp:

LINE/COL

ERROR

--------------

--------------------------------------------

3/27

PL/SQL-00103: Encountered the symbol "EMPNO" wh. . .

5/0

PL/SQL-00103: Encountered the symbol "END" when . . .

7-34 Oracle Database Application Developer's Guide - Fundamentals

Соседние файлы в папке Oracle 10g