dbms_datapump.get_dumpfile_info can't read directory when compiled in stored procedure












0















I'm creating a stored procedure to load (impdp) a Datapump database dump.



I am trying to get the dump file's creation date (to compare with the date of a previously loaded dump), using DBMS_DATAPUMP.GET_DUMPFILE_INFO, like in this example.



When running in an anonymous block (like below), it runs fine, outputting the dump file's creation date. However, when this same block is adapted and compiled in a stored procedure, I get the ORA-39087 error (Directory name is invalid).



DECLARE 
dumpfile VARCHAR2(256) := 'my_file.dp';
dir VARCHAR2(30) := 'MY_DIR';
info ku$_dumpfile_info;
ft NUMBER;
BEGIN
sys.dbms_datapump.get_dumpfile_info(dumpfile, dir, info, ft);
FOR rec IN (SELECT * FROM TABLE (info) WHERE item_code = 6 ) LOOP
dbms_output.put_line(rec.value);
END LOOP;
END;


The directory exists. The name is valid. When I run



SELECT * FROM datapump_dir_objs;


with the same user, I can see that the user has READ and WRITE privileges on the directory. Oracle version is 11g Release 11.2.0.4.0.



Any light on what I am doing wrong?



Thanks in advance.










share|improve this question


















  • 3





    Does the user have read and write privileges granted directly to them, or via a role? (A quick way to check is to see whether your query still shows the same data after you do set role none.)

    – Alex Poole
    Nov 20 '18 at 18:39













  • Thanks @AlexPoole ! The privilege is granted by a role. I added AUTHID CURRENT_USER to the procedure's header and all went fine.

    – Fernando Volquind
    Nov 21 '18 at 10:45


















0















I'm creating a stored procedure to load (impdp) a Datapump database dump.



I am trying to get the dump file's creation date (to compare with the date of a previously loaded dump), using DBMS_DATAPUMP.GET_DUMPFILE_INFO, like in this example.



When running in an anonymous block (like below), it runs fine, outputting the dump file's creation date. However, when this same block is adapted and compiled in a stored procedure, I get the ORA-39087 error (Directory name is invalid).



DECLARE 
dumpfile VARCHAR2(256) := 'my_file.dp';
dir VARCHAR2(30) := 'MY_DIR';
info ku$_dumpfile_info;
ft NUMBER;
BEGIN
sys.dbms_datapump.get_dumpfile_info(dumpfile, dir, info, ft);
FOR rec IN (SELECT * FROM TABLE (info) WHERE item_code = 6 ) LOOP
dbms_output.put_line(rec.value);
END LOOP;
END;


The directory exists. The name is valid. When I run



SELECT * FROM datapump_dir_objs;


with the same user, I can see that the user has READ and WRITE privileges on the directory. Oracle version is 11g Release 11.2.0.4.0.



Any light on what I am doing wrong?



Thanks in advance.










share|improve this question


















  • 3





    Does the user have read and write privileges granted directly to them, or via a role? (A quick way to check is to see whether your query still shows the same data after you do set role none.)

    – Alex Poole
    Nov 20 '18 at 18:39













  • Thanks @AlexPoole ! The privilege is granted by a role. I added AUTHID CURRENT_USER to the procedure's header and all went fine.

    – Fernando Volquind
    Nov 21 '18 at 10:45
















0












0








0








I'm creating a stored procedure to load (impdp) a Datapump database dump.



I am trying to get the dump file's creation date (to compare with the date of a previously loaded dump), using DBMS_DATAPUMP.GET_DUMPFILE_INFO, like in this example.



When running in an anonymous block (like below), it runs fine, outputting the dump file's creation date. However, when this same block is adapted and compiled in a stored procedure, I get the ORA-39087 error (Directory name is invalid).



DECLARE 
dumpfile VARCHAR2(256) := 'my_file.dp';
dir VARCHAR2(30) := 'MY_DIR';
info ku$_dumpfile_info;
ft NUMBER;
BEGIN
sys.dbms_datapump.get_dumpfile_info(dumpfile, dir, info, ft);
FOR rec IN (SELECT * FROM TABLE (info) WHERE item_code = 6 ) LOOP
dbms_output.put_line(rec.value);
END LOOP;
END;


The directory exists. The name is valid. When I run



SELECT * FROM datapump_dir_objs;


with the same user, I can see that the user has READ and WRITE privileges on the directory. Oracle version is 11g Release 11.2.0.4.0.



Any light on what I am doing wrong?



Thanks in advance.










share|improve this question














I'm creating a stored procedure to load (impdp) a Datapump database dump.



I am trying to get the dump file's creation date (to compare with the date of a previously loaded dump), using DBMS_DATAPUMP.GET_DUMPFILE_INFO, like in this example.



When running in an anonymous block (like below), it runs fine, outputting the dump file's creation date. However, when this same block is adapted and compiled in a stored procedure, I get the ORA-39087 error (Directory name is invalid).



DECLARE 
dumpfile VARCHAR2(256) := 'my_file.dp';
dir VARCHAR2(30) := 'MY_DIR';
info ku$_dumpfile_info;
ft NUMBER;
BEGIN
sys.dbms_datapump.get_dumpfile_info(dumpfile, dir, info, ft);
FOR rec IN (SELECT * FROM TABLE (info) WHERE item_code = 6 ) LOOP
dbms_output.put_line(rec.value);
END LOOP;
END;


The directory exists. The name is valid. When I run



SELECT * FROM datapump_dir_objs;


with the same user, I can see that the user has READ and WRITE privileges on the directory. Oracle version is 11g Release 11.2.0.4.0.



Any light on what I am doing wrong?



Thanks in advance.







oracle plsql directory datapump






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 18:35









Fernando VolquindFernando Volquind

153




153








  • 3





    Does the user have read and write privileges granted directly to them, or via a role? (A quick way to check is to see whether your query still shows the same data after you do set role none.)

    – Alex Poole
    Nov 20 '18 at 18:39













  • Thanks @AlexPoole ! The privilege is granted by a role. I added AUTHID CURRENT_USER to the procedure's header and all went fine.

    – Fernando Volquind
    Nov 21 '18 at 10:45
















  • 3





    Does the user have read and write privileges granted directly to them, or via a role? (A quick way to check is to see whether your query still shows the same data after you do set role none.)

    – Alex Poole
    Nov 20 '18 at 18:39













  • Thanks @AlexPoole ! The privilege is granted by a role. I added AUTHID CURRENT_USER to the procedure's header and all went fine.

    – Fernando Volquind
    Nov 21 '18 at 10:45










3




3





Does the user have read and write privileges granted directly to them, or via a role? (A quick way to check is to see whether your query still shows the same data after you do set role none.)

– Alex Poole
Nov 20 '18 at 18:39







Does the user have read and write privileges granted directly to them, or via a role? (A quick way to check is to see whether your query still shows the same data after you do set role none.)

– Alex Poole
Nov 20 '18 at 18:39















Thanks @AlexPoole ! The privilege is granted by a role. I added AUTHID CURRENT_USER to the procedure's header and all went fine.

– Fernando Volquind
Nov 21 '18 at 10:45







Thanks @AlexPoole ! The privilege is granted by a role. I added AUTHID CURRENT_USER to the procedure's header and all went fine.

– Fernando Volquind
Nov 21 '18 at 10:45














1 Answer
1






active

oldest

votes


















0














The problem was that the READ and WRITE privileges on the directory were added via a role. By default, anonymous blocks are executed with the current user's privileges, but stored procedures are not.



I added AUTHID CURRENT_USER to the procedure's header and managed to access my directory.



Thanks to Alex Poole for the insight.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399406%2fdbms-datapump-get-dumpfile-info-cant-read-directory-when-compiled-in-stored-pro%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The problem was that the READ and WRITE privileges on the directory were added via a role. By default, anonymous blocks are executed with the current user's privileges, but stored procedures are not.



    I added AUTHID CURRENT_USER to the procedure's header and managed to access my directory.



    Thanks to Alex Poole for the insight.






    share|improve this answer




























      0














      The problem was that the READ and WRITE privileges on the directory were added via a role. By default, anonymous blocks are executed with the current user's privileges, but stored procedures are not.



      I added AUTHID CURRENT_USER to the procedure's header and managed to access my directory.



      Thanks to Alex Poole for the insight.






      share|improve this answer


























        0












        0








        0







        The problem was that the READ and WRITE privileges on the directory were added via a role. By default, anonymous blocks are executed with the current user's privileges, but stored procedures are not.



        I added AUTHID CURRENT_USER to the procedure's header and managed to access my directory.



        Thanks to Alex Poole for the insight.






        share|improve this answer













        The problem was that the READ and WRITE privileges on the directory were added via a role. By default, anonymous blocks are executed with the current user's privileges, but stored procedures are not.



        I added AUTHID CURRENT_USER to the procedure's header and managed to access my directory.



        Thanks to Alex Poole for the insight.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 10:51









        Fernando VolquindFernando Volquind

        153




        153






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399406%2fdbms-datapump-get-dumpfile-info-cant-read-directory-when-compiled-in-stored-pro%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules