JOB 频繁出现ORA-30625:method dispatch on NULL SELF argument is disallowed。
这篇文章将对此错误进行重现并分析其原因
1. 创建type
CREATE OR REPLACE TYPE EMPLOYEE_TP AS OBJECT(
EMPLOYEE_ID NUMBER,
IN_DATE DATE,
MGR_ID NUMBER(1),
DEPT_NO NUMBER(1),
member procedure delete_employee_id(n in number)
);
2. 创建测试表
CREATE TABLE EMPLOYEE OF EMPLOYEE_TP(
EMPLOYEE_ID PRIMARY KEY
);
3. 创建type body
create or replace type body EMPLOYEE_TP as
member procedure
delete_employee_id(n in number) is
begin
DELETE FROM EMPLOYEE E
WHERE E.EMPLOYEE_ID = n;
end;
end;
4. insert 测试数据
insert into EMPLOYEE values (EMPLOYEE_TP(1,TO_DATE('12/12/12','DD-MM-YY'),0,0));
5. 引用type并执行
declare
x EMPLOYEE_TP;
begin
x.delete_employee_id('1');
end;
输出结果如下:
ORA-30625: method dispatch on NULL SELF argument is disallowed
ORA-06512: at line 4
30625. 00000 - "method dispatch on NULL SELF argument is disallowed"
*Cause: A member method of a type is being invoked with a NULL SELF
argument.
*Action: Change the method invocation to pass in a valid self argument.
6.原因
User-defined types, just like collections, are atomically null, until you initialize the object by calling the constructor for its object type
用户定义的type,就像集合一样,在原子上是null的,直到通过调用其对象类型的构造函数来初始化该对象
也就是说对于自定义的type,需要使用构造函数进行初始化后才能调用其方法
所以,你需要这样做:
7. 正确的方式
declare
x employee_tp :=NEW employee_tp(null,null,null,null);
begin
x.delete_employee_id('1');
end;
结果输出如下:
已順利完成 PL/SQL 程序.