我有下一个存储过程:
create or replace procedure generate_tables_for_project
as
begin
execute immediate 'create table farmers (email nvarchar2(30) PRIMARY KEY, fname nvarchar2(30), lname nvarchar2(30), password nvarchar2(30), farmname nvarchar2(30), region nvarchar2(30), address nvarchar2(30) )';
execute immediate 'create table ISRAELLOCATIONS (region nvarchar2(30), regionID number(2) PRIMARY KEY )';
execute immediate 'create table product (name nvarchar2(30), productID number(2) PRIMARY KEY )';
execute immediate 'create table sub_product (name nvarchar2(30), sub_productID number(3) PRIMARY KEY , product_id number(2) REFERENCES product( productID))'; EXCEPTION
WHEN OTHERS THEN IF SQLCODE = -955
THEN
raise_application_error(-20001, 'Tables Exist!!!');--DBMS_OUTPUT.PUT_LINE( 'Data already exist!!!');
END IF;
end generate_tables_for_project;
现在,当我在SQLdeveloper中激活它的程序时,表格将会创建。 但我再次激活我想只得到-955表存在错误。 但我也得到错误:
ORA-20001: Tables Exist!!!
ORA-06512: at "HR.GENERATE_TABLES_FOR_PROJECT", line 11
ORA-06512: at line 2
ORA-20001错误是我为0955引发的错误所以这很好, 但是另外两个是什么?!
谢谢!
答案 0 :(得分:0)
其他两个错误是因为HR.GENERATE_TABLES_FOR_PROJECT
过程出错,错误排在第2行。
答案 1 :(得分:0)
它显示错误堆栈,并不意味着您有更多错误;例如:
SQL> CREATE OR REPLACE PROCEDURE test_error IS
2 BEGIN
3 raise_application_error(-20001, 'Error 1');
4 EXCEPTION
5 WHEN OTHERS THEN
6 raise_application_error(-20002, 'Error 2');
7 END;
8 /
Procedure created.
SQL> exec test_error
BEGIN test_error; END;
*
ERROR at line 1:
ORA-20002: Error 2
ORA-06512: at "SIUCONTAB.TEST_ERROR", line 6
ORA-06512: at line 1