Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PLS-00201: identifier UTIL_FILE must be declared

Tags:

sql

oracle

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:

http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:235814350980

which basically writes a function and uses the UTIL_FILE object to create and write to a file and add delimiters.

I receive the follow error when I try and create the function in Oracle SQL Developer:

PLS-00201: identifier UTIL_FILE must be declared. 

When I run the following command:

select owner, object_type from all_objects where object_name = 'UTL_FILE' 

The result is:

OWNER      Object Type
---------  -----------
PUBLIC     SYNONYM

EDIT:

Running:

GRANT EXECUTE ON UTL_FILE TO PUBLIC

Gives:

Error starting at line 2 in command:
GRANT EXECUTE ON UTL_FILE TO PUBLIC
Error report:
SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

What is the problem?

like image 887
Kristy Welsh Avatar asked Nov 20 '13 20:11

Kristy Welsh


People also ask

What is a Utl_file?

The UTL_FILE package lets your PL/SQL programs read and write operating system (OS) text files. It provides a restricted version of standard OS stream file input/output (I/O).

Which method in Utl_file is used to open the file?

FOPEN returns a file handle, which must be passed to all subsequent procedures that operate on that file. The specific contents of the file handle are private to the UTL_FILE package, and individual components should not be referenced or changed by the UTL_FILE user. Handle to open file.


2 Answers

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.

like image 118
Przemyslaw Kruglej Avatar answered Sep 30 '22 18:09

Przemyslaw Kruglej


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;
like image 38
Alen Oblak Avatar answered Sep 30 '22 18:09

Alen Oblak