Home » SQL & PL/SQL » SQL & PL/SQL » MV creation error PLS-512: Cannot directly access remote package variable or cursor (Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi)
MV creation error PLS-512: Cannot directly access remote package variable or cursor [message #613450] Wed, 07 May 2014 02:23 Go to next message
Buchas
Messages: 101
Registered: March 2006
Senior Member
Hello,

I am trying to create a materialized view that uses DBlink:

CREATE MATERIALIZED VIEW DWPIPE.RETURNS_FACT_MV 
  NOLOGGING USING INDEX TABLESPACE INDX
    REFRESH COMPLETE
AS 
SELECT
  SUM(POLISAS.GET_RODIKLIS.SKOLA_PO_NUTRAUKIMO_PROD@DISBIG_DISNEW( AP.ID, NULL)) AS SKOLA_PO_NUTRAUKIMO
FROM
  POLISAS.APDRAUSTAS_PRODUKTAS_T@DISBIG_DISNEW AP


I get the following error:
ORA-06552: PL/SQL: Statement ignored
ORA-06553: PLS-512: Implementation Restriction: 'VALIUTOS_TIPAS_BAZINE': Cannot
directly access remote package variable or cursor

Procedure SKOLA_PO_NUTRAUKIMO_PROD is on another DB and is declared in the following way:

CREATE OR REPLACE PACKAGE POLISAS.GET_RODIKLIS AS

    VALIUTOS_TIPAS_BAZINE          CONSTANT NUMBER := 0;

    FUNCTION SKOLA_PO_NUTRAUKIMO_PROD(N_AP_ID_IPARM               IN NUMBER, 
                                      DT_APSKAICIUOTI_DATAI_IPARM IN DATE, 
                                      VALIUTOS_TIPAS_PARM         IN NUMBER DEFAULT VALIUTOS_TIPAS_BAZINE )
        RETURN NUMBER;

END;


If I replace a named constant VALIUTOS_TIPAS_BAZINE with its value 0, I get no error creating MV in another DB.
I also get no error, if I only execute the SELECT statement of MV in another DB.
I also get no error, if I create MV in the same DB (without DB link).
Now please tell me, why can't I use a named constant in a function declaration while creating a materialized view in another DB?
Re: MV creation error PLS-512: Cannot directly access remote package variable or cursor [message #613451 is a reply to message #613450] Wed, 07 May 2014 02:41 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Seems to me that the answer is in the error message. Oracle hasn't written underlying MV code to allow you to do what you want.
Re: MV creation error PLS-512: Cannot directly access remote package variable or cursor [message #613452 is a reply to message #613450] Wed, 07 May 2014 02:46 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Try to create a function (in the GET_RODIKLIS package) which returns VALIUTOS_TIPAS_BAZINE. Then modify DEFAULT value for the VAILUTOS_TIPAS_PARAM so that it calls a function (that returns VALIUTOS_TIPAS_BAZINE) instead of VALIUTOS_TIPAS_BAZINE itself.

Something like
CREATE OR REPLACE PACKAGE POLISAS.GET_RODIKLIS AS

    VALIUTOS_TIPAS_BAZINE          CONSTANT NUMBER := 0;

    function f_valiutos_tipas_bazine return number;

    FUNCTION SKOLA_PO_NUTRAUKIMO_PROD(N_AP_ID_IPARM               IN NUMBER, 
                                      DT_APSKAICIUOTI_DATAI_IPARM IN DATE, 
                                      VALIUTOS_TIPAS_PARM         IN NUMBER DEFAULT f_valiutos_tipas_bazine )
        RETURN NUMBER;

END;

create or replace package body polisas.get_rodiklis as
  ...
  function f_valiutos_tipas_bazine return number is
    begin
      return polisas.get_rodiklis.valiutos_tipas_bazine;
    end;
  ...
end;
Re: MV creation error PLS-512: Cannot directly access remote package variable or cursor [message #613455 is a reply to message #613452] Wed, 07 May 2014 03:26 Go to previous messageGo to next message
Buchas
Messages: 101
Registered: March 2006
Senior Member
Thanks Littlefoot, I didnt know it is possible to use a function in DEFAULT, it works.
But I have decided to change my MV query specifying default value there:

SUM(POLISAS.GET_RODIKLIS.SKOLA_PO_NUTRAUKIMO_PROD@DISBIG_DISNEW( AP.ID, NULL, 0)) AS SKOLA_PO_NUTRAUKIMO


Weird situation anyway.
Re: MV creation error PLS-512: Cannot directly access remote package variable or cursor [message #613456 is a reply to message #613455] Wed, 07 May 2014 03:30 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Buchas wrote on Wed, 07 May 2014 10:26
I didnt know it is possible to use a function in DEFAULT


Yes, you knew it (just didn't know that you know it). I guess you must have used something like
function f_something (par_date in date default SYSDATE) return ...
                                                  ^
                                                  |
                                                This!

SYSDATE is a function.
Re: MV creation error PLS-512: Cannot directly access remote package variable or cursor [message #613457 is a reply to message #613456] Wed, 07 May 2014 03:41 Go to previous messageGo to next message
Buchas
Messages: 101
Registered: March 2006
Senior Member
"default SYSDATE" - there is no such construction in all of my packages Smile though there are 38 packages with "default"
Re: MV creation error PLS-512: Cannot directly access remote package variable or cursor [message #613458 is a reply to message #613457] Wed, 07 May 2014 03:45 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Well, it seems that I guessed it wrong.
Re: MV creation error PLS-512: Cannot directly access remote package variable or cursor [message #613468 is a reply to message #613450] Wed, 07 May 2014 07:08 Go to previous message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Buchas wrote on Wed, 07 May 2014 03:23
Now please tell me, why can't I use a named constant in a function declaration while creating a materialized view in another DB?


Well, I agree Oracle could do a better job realizing it is package public global constant not package public global variable. Anyway, there is a bit of a "catch 22". Moving package public global variable/constant/cursor from package specification to package body would make it private and would eliminate the issue. However constant is used as parameter default value in function specification which creates that "catch 22". So what could you do? You could make constant private and use overloading:

CREATE OR REPLACE
  PACKAGE GET_RODIKLIS
    AS
      FUNCTION SKOLA_PO_NUTRAUKIMO_PROD(
                                        N_AP_ID_IPARM               IN NUMBER, 
                                        DT_APSKAICIUOTI_DATAI_IPARM IN DATE, 
                                        VALIUTOS_TIPAS_PARM         IN NUMBER
                                       )
        RETURN NUMBER;
      FUNCTION SKOLA_PO_NUTRAUKIMO_PROD(
                                        N_AP_ID_IPARM               IN NUMBER, 
                                        DT_APSKAICIUOTI_DATAI_IPARM IN DATE
                                       )
        RETURN NUMBER;
END;
/
CREATE OR REPLACE
  PACKAGE BODY GET_RODIKLIS
    AS
      VALIUTOS_TIPAS_BAZINE CONSTANT NUMBER := 0;
      FUNCTION SKOLA_PO_NUTRAUKIMO_PROD(
                                        N_AP_ID_IPARM               IN NUMBER, 
                                        DT_APSKAICIUOTI_DATAI_IPARM IN DATE, 
                                        VALIUTOS_TIPAS_PARM         IN NUMBER
                                       )
        RETURN NUMBER
        IS
        BEGIN
            RETURN N_AP_ID_IPARM;
      END;
      FUNCTION SKOLA_PO_NUTRAUKIMO_PROD(
                                        N_AP_ID_IPARM               IN NUMBER, 
                                        DT_APSKAICIUOTI_DATAI_IPARM IN DATE
                                       )
        RETURN NUMBER
        IS
        BEGIN
            RETURN SKOLA_PO_NUTRAUKIMO_PROD(
                                            N_AP_ID_IPARM, 
                                            DT_APSKAICIUOTI_DATAI_IPARM, 
                                            VALIUTOS_TIPAS_BAZINE
                                           );
      END;
END;
/


Now:

SQL> CREATE MATERIALIZED VIEW RETURNS_FACT_MV 
  2    NOLOGGING
  3    USING INDEX
  4    REFRESH COMPLETE
  5    AS 
  6      SELECT  SUM(GET_RODIKLIS.SKOLA_PO_NUTRAUKIMO_PROD@D1MAXTRAN(1,NULL)) AS SKOLA_PO_NUTRAUKIMO
  7        FROM  DUAL@D1MAXTRAN AP
  8  /

Materialized view created.

SQL> SELECT  *
  2    FROM  RETURNS_FACT_MV
  3  /

SKOLA_PO_NUTRAUKIMO
-------------------
                  1

SQL> 


Sėkmės!

SY.
Previous Topic: ORA-00905 error
Next Topic: unable truncate table in plsql block
Goto Forum:
  


Current Time: Fri Apr 26 16:36:21 CDT 2024