[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 982
  • Last Modified:

External Table creation inside PLSQL Package error...

Hi Experts..


I am trying to create an External Table inside PLSQL Package but an error "Insufficient Priviledges" occurs...

DECLARE
issuccess BOOLEAN;
BEGIN

-- Now call the stored program
  my_package.proc_load_file('INCOMING','SA202_PPD_WARRANTY_20041010_09101010.txt',issuccess);

-- Output the results
IF issuccess THEN
  dbms_output.put_line('issuccess = TRUE');
ELSE
  dbms_output.put_line('issuccess = FALSE');
END IF;

EXCEPTION
WHEN OTHERS THEN
  dbms_output.put_line(SubStr('Error '||TO_CHAR(SQLCODE)||': '||SQLERRM, 1, 255));
RAISE;
END;



Here is my Package...

PACKAGE BODY MY_PACKAGE AS
PROCEDURE PROC_LOAD_FILE (
        varFileDirectory        IN VARCHAR2
        , varFile               IN VARCHAR2
        , isSuccess             OUT BOOLEAN)
IS
      varTransposedPhoneNumber    VARCHAR2(30) := '';
    varMobileNumber             VARCHAR2(30) := '';
    varSourceTransactionDate    VARCHAR2(15) := '';
    varTransactionIdentifier    VARCHAR2(30) := '';
   
    varDelimiter                VARCHAR2(1) := ',';
    varSQL                      VARCHAR2(1000);
BEGIN
    BEGIN
        varSQL :=
            'CREATE TABLE PREPAID_WARRANTY_EXT_TBL
            (
                TRANSPOSED_PHONE_NUMBER VARCHAR2(30),
                MOBILE_NUMBER VARCHAR2(30),
                SOURCE_TRANSACTION_DATE VARCHAR2(15),
                TRANSACTION_IDENTIFIER VARCHAR2(30)
            )
            ORGANIZATION EXTERNAL
            (
                TYPE ORACLE_LOADER
                DEFAULT DIRECTORY ' || varFileDirectory || '
                ACCESS PARAMETERS
                (
                    FIELDS TERMINATED BY ' || '''' || varDelimiter || '''' || '
                )
                LOCATION (' || '''' || varFile || '''' || ')
            )';
        --DBMS_OUTPUT.PUT_LINE('varSQL is [' || varSQL || ']');
        EXECUTE IMMEDIATE(varSQL);
        COMMIT;
        DBMS_OUTPUT.PUT_LINE('successfull create table');
    --EXCEPTION
        --WHEN OTHERS THEN
           --DBMS_OUTPUT.PUT_LINE('other exceptions create table');
    END;
END PROC_LOAD_FILE;
END MY_PACKAGE;



however, if I am to create an External Table outside of PLSQL Package, it is successfull...

CREATE TABLE PREPAID_WARRANTY_EXT_TBL
    (
         TRANSPOSED_PHONE_NUMBER    VARCHAR2(30),
         MOBILE_NUMBER              VARCHAR2(30),
         SOURCE_TRANSACTION_DATE    VARCHAR2(15),
         TRANSACTION_IDENTIFIER     VARCHAR2(30)
    )
    ORGANIZATION EXTERNAL
    (
         TYPE ORACLE_LOADER
         DEFAULT DIRECTORY INCOMING
         ACCESS PARAMETERS
         (
            FIELDS TERMINATED BY ','
         )
         LOCATION ('SA202_PPD_WARRANTY_20041010_09101010.txt')
    );



May I ask what do I need to set or configure with regards to priviledges...?


Thanks in advanced experts...   =)
0
aris_datuin
Asked:
aris_datuin
  • 2
2 Solutions
 
baonguyen1Commented:
Hi aris_datuin,

If you grant priviledge to user via role you may get "insufficient Priviledges" when executing PLSQL package. What you need to do is grant Create Any Table to that use directly then try again;

SQL>grant create any table to <schema>;

Hope this helps
0
 
Pierrick LOUBIERCommented:
Add AUTHID CURRENT_USER to your procedure :

PROCEDURE PROC_LOAD_FILE (
        varFileDirectory        IN VARCHAR2
        , varFile               IN VARCHAR2
        , isSuccess             OUT BOOLEAN) AUTHID CURRENT_USER
IS
0
 
aris_datuinAuthor Commented:
That was fast...!   And it worked already...

I would just like to ask, what does AUTHID CURRENT_USER is for...?


Thanks again experts...   =)
0
 
Pierrick LOUBIERCommented:
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now