PLS-00201: identifier UTIL_FILE must be declared

前端 未结 5 1067
忘了有多久
忘了有多久 2021-01-12 05:45

I\'m trying to export data from a query into a csv file from Oracle Enterprise Express installed on a Windows Server 2008 machine.

I\'ve found this solution:

相关标签:
5条回答
  • 2021-01-12 06:12

    Aside from the possible lack of permissions that other answers have covered, your question says the error you get is:

    PLS-00201: identifier UTIL_FILE must be declared
    

    That suggests you've referenced UTIL_FILE, rather than the built-in package UTL_FILE, in your function. It might be an error you've introduced writing the question, of course, but you used it in the text too so maybe you have got the package name wrong in your code, if you didn't just copy-and-paste Tom's code.

    You'll still need execute privileges on UTL_FILE anyway, if you don't have them already.

    0 讨论(0)
  • 2021-01-12 06:15

    As user: h_djebli pointed out in his comment you need to be connected as SYS user in the first place.

    To do that, you have to be in your oracle home directory :

    cd $ORACLE_HOME
    

    Then execute :

    sqlplus / as sysdba
    

    sqlplus will start in your terminal and you'll be connected as the SYS user.

    You can finally write the GRANT command in your sqlplus console :

    GRANT EXECUTE ON SYS.utl_file TO your_db_username;
    
    0 讨论(0)
  • 2021-01-12 06:17

    Users do not have execute permission on UTL_FILE by default. To use UTL_FILE, an ADMIN user or instance administrator must explicitly GRANT EXECUTE permission on it, such as in the following example:

    GRANT EXECUTE ON SYS.UTL_FILE TO scott;
    
    0 讨论(0)
  • 2021-01-12 06:18

    Seems like lack of privileges to me. Often PUBLIC user has EXECUTE privilege granted on that package, but the privilege may be revoked.

    You can check if PUBLIC has that privilege by issuing the following query:

    SELECT * FROM all_tab_privs WHERE grantee = 'PUBLIC' AND table_name = 'UTL_FILE';
    

    If there are no rows returned, try granting the execute privilege to either the user you are logged as, or to PUBLIC, as some privileged user, for example SYS:

    GRANT EXECUTE ON SYS.utl_file TO user_name;
    

    Edit

    You must grant the privilege while being logged as, for example, SYS user.

    0 讨论(0)
  • 2021-01-12 06:27

    We can do this via cmd, with these steps:

    1. Login as sysdba (connect sys as sysdba + enter password as sys_password)
    2. grant execute on utl_file to <user_name>.
    3. now we can check by query :'SELECT * FROM all_tab_privs WHERE grantee = 'PUBLIC' AND table_name = 'UTL_FILE';'
    0 讨论(0)
提交回复
热议问题