2013-12-16 127 views
1

Oracle不斷給我發出此錯誤:ORA-30625:方法調度爲NULL SELF參數不允許。PL/SQL ORA-30625:方法調度爲NULL SELF參數不允許

ORA-30625:對NULL SELF參數方法分派是不允許

的代碼如下:直到您構造函數調用創建

 CREATE OR REPLACE TYPE PEDIDO_TP AS OBJECT(
     ID_PEDIDO NUMBER, 
     DATA_PAGAMENTO DATE, 
     CANCELADO NUMBER(1), 
     PENDURADO NUMBER(1), 
     member procedure cancelapedido(n in number) 
     ); 

create or replace type body PEDIDO_TP as member procedure cancelapedido(n in number) is begin DELETE FROM PEDIDO p WHERE p.ID_PEDIDO = n; end; end; CREATE TABLE PEDIDO OF PEDIDO_TP( ID_PEDIDO PRIMARY KEY ); insert into PEDIDO values (PEDIDO_TP(1,'12/12/12',0,0)); declare x PEDIDO_TP; begin x.cancelapedido('1'); end;<code>
+1

可能重複成員過程NULL SELF參數Oracle](http://stackoverflow.com/questions/2319022/calling-member-procedure-null-self-argument-oracle) – user272735

回答

3

你的對象爲null。從Oracle文檔,

User-defined types, just like collections, are atomically null, until you initialize the object by calling the constructor for its object type

所以,你需要這樣做:

declare 
x PEDIDO_TP; --reference to the object 

begin 
    x := PEDIDO_TP(,,, all your parameters,,,); --assign created object to the reference. 
end; 

鏈接documentation

0

你需要調用該對象的構造函數,你可以做到這一點的時候你聲明變量。例如:

聲明 x PEDIDO_TP:= PEDIDO_TP.CONSTRUCT; - 引用對象並調用構造函數。

0
**--ORA-30625 (A member method of a type is being invoked with a NULL SELF argument.)** 

The issue is simulated with the below cases 

Three Cases:- 

**1- Invoking a method without initializing the object 
2- Data is not there in the Payload 
3- Data is null in the payload** 

--Try to execute the below Scripts 

--CREATE TYPE & TYPE BODY 

CREATE OR REPLACE TYPE TEST_TYPE AS OBJECT(
     ID NUMBER, 
     DIGIT NUMBER(1), 
     member FUNCTION FACT_CAL(n in number) RETURN NUMBER); 

create or replace type body TEST_TYPE as 
    member FUNCTION FACT_CAL(n in number) RETURN NUMBER is 
    begin 
    RETURN SELF.ID * SELF.DIGIT * n; 
    end; 
END; 

**--1- Invoking a method without initializing the object** 

--Issue arises here 
DECLARE 
    r1 TEST_TYPE; 
BEGIN 
-- R1 := TEST_TYPE(1,2); 
    DBMS_OUTPUT.put_line(R1.FACT_CAL(2)); 
END; 

-----NOW EXECUTE BELOW(issue is resolved here)------ 

**Solution:-** 

DECLARE 
    r1 TEST_TYPE; 
BEGIN 
    R1 := TEST_TYPE(1,2); 
    DBMS_OUTPUT.put_line(R1.FACT_CAL(2)); 
END; 

**--2- Data is not there in the Payload** 

-----EXECUTE BELOW(Issue arises here)------ 

DECLARE 
    r1 TEST_TYPE; 
    r2 sys.anydata; 
    r3 number; 
BEGIN 
-- R1 := TEST_TYPE(null,null); 
r3:=r2.getObject(r1); 
    DBMS_OUTPUT.put_line(DBMS_TYPES.SUCCESS); 
END; 

---Now Execute below(--issue is resolved here)---- 

**Solution :-** 

DECLARE 
    r1 TEST_TYPE; 
    r2 sys.anydata; 
    r3 number; 
BEGIN 
-- R1 := TEST_TYPE(null,null); 
r2:= sys.anydata.ConvertObject(r1); 
r3:=r2.getObject(r1); 
    DBMS_OUTPUT.put_line(DBMS_TYPES.SUCCESS); 
END; 

**-- 3- Data is null in the payload** 

CREATE OR REPLACE TYPE TEST_TYPE1 AS OBJECT(
     ID NUMBER, 
     DIGIT NUMBER(1)); 

create table anydata 
(id number, 
data sys.anydata); 

    insert into anydata values (1, null); 

CREATE OR REPLACE FUNCTION GET_OBJ_TYPE(IN_ANYDATA SYS.ANYDATA) 
    RETURN TEST_TYPE1 IS 

    V_ANYDATA SYS.ANYDATA := IN_ANYDATA; 
    V_BE_DATA TEST_TYPE1 ; 
    V_RETURN PLS_INTEGER; 
BEGIN 
V_RETURN := SYS.ANYDATA.GETOBJECT(SELF => V_ANYDATA, OBJ => V_BE_DATA); 
RETURN V_BE_DATA; 
END GET_OBJ_TYPE; 

--EXECUTE THE QUERY(Issue arises here) 

select GET_OBJ_TYPE(data) from anydata; 

--NOTE :- PROBLEM IS WHEN THE ANYDATA VALUE IS NULL THIS DATA CANT CONVERT THE PAYLOAD TO SPECIFIC OBJECT TYPE . 

-**-SOLUTION** :- 

(CONVERT THE 'NULL' ENTRY TO SYS.ANYDATA TYPE) --issue is resolved here 


CREATE OR REPLACE FUNCTION GET_OBJ_TYPE(IN_ANYDATA SYS.ANYDATA) 
    RETURN TEST_TYPE1 IS 

    V_ANYDATA SYS.ANYDATA := IN_ANYDATA; 
    V_BE_DATA TEST_TYPE1 ; 
    V_RETURN PLS_INTEGER; 
BEGIN 
    V_ANYDATA:= sys.anydata.ConvertObject(V_BE_DATA);--- ADD THIS LINE WHICH CONVERTS 'NULL' TO THE SYS.ANYDATA TYPE 
    V_RETURN := SYS.ANYDATA.GETOBJECT(SELF => V_ANYDATA, OBJ => V_BE_DATA); 

    RETURN V_BE_DATA; 
END GET_OBJ_TYPE; 

--NOW EXECUTE THE QUERY`enter code here` 
select GET_OBJ_TYPE(data) from anydata; 


HOPE THIS IS HELPFUL ... 
0

它與oracle ACL(很可能)有關,至少我們可以通過解決ACL問題來解決這個問題。

確保端口可用於特定域

select acl , host , lower_port , upper_port from DBA_NETWORK_ACLS; 

,並確保用戶有足夠的權限

select acl , principal , privilege , is_grant from DBA_NETWORK_ACL_PRIVILEGES; 

ACL教程[調用的HERE