0

I got the object T_CONTRIBUYENTE, it has the attribute HABILITADO and the member function P_VERIFICAR_HABILITACION. The function is supposed to assign 'S' to self.HABILITADO, but I don't know if that's possible. When I run the code above, I get the error

PLS-00363 "The expression 'SELF.HABILITADO' can't be used as an assignment target.

I think is more of a conceptual problem, and I don't have it very clear. I googled but couldn't find anything helpful.

    CREATE OR REPLACE TYPE T_CONTRIBUYENTE AS OBJECT
    (RUC VARCHAR2(11),
    NOMBRE VARCHAR2(50),
    APELLIDO_RAZON VARCHAR2(50),
    TIPO_CONTRIBUYENTE VARCHAR2(1),
    HABILITADO VARCHAR2(1),
    FECHA_VALIDEZ DATE,
    MEMBER FUNCTION P_VERIFICAR_HABILITACION RETURN VARCHAR2,
    STATIC FUNCTION F_OBTENER_CONTRIBUYENTE(RUC VARCHAR2) RETURN T_CONTRIBUYENTE);
    /
    CREATE OR REPLACE TYPE BODY T_CONTRIBUYENTE IS
        MEMBER FUNCTION P_VERIFICAR_HABILITACION RETURN VARCHAR2 IS
        CURSOR C_ULTPAGO IS
            SELECT MAX(p.fecha_pago) 
            FROM PAGOS p JOIN DECLARACION d ON p.id=d.id
            WHERE d.RUC = SELF.RUC;
        FECHA_PAGO DATE;
        BEGIN
            OPEN C_ULTPAGO;
            FETCH C_ULTPAGO INTO FECHA_PAGO;
            CLOSE C_ULTPAGO;
            IF(MONTHS_BETWEEN(SYSDATE, FECHA_PAGO) <=1) THEN
                SELF.HABILITADO := 'S';
            ELSE
                SELF.HABILITADO := 'N';
            END IF;
       END;
END;

1 Answer 1

0

When we're just reading the attributes of the SELF object we can rely on the implicit parameter for the function. However, to modify the object we need to explicitly define the parameter. So you need to change the signature of the member function to look like this:

MEMBER FUNCTION P_VERIFICAR_HABILITACION (SELF IN OUT NOCOPY T_CONTRIBUYENTE) RETURN VARCHAR2 

Incidentally, your function doesn't actually return anything, so it will fail at runtime. If you don't want it to return a value then you should change it to be a MEMBER PROCEDURE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.