Home » SQL & PL/SQL » SQL & PL/SQL » Directory Name with UTL_FILE.FOPEN() (Oracle, 12.2, Unix)
Directory Name with UTL_FILE.FOPEN() [message #686042] |
Fri, 03 June 2022 18:46  |
Duane
Messages: 585 Registered: December 2002
|
Senior Member |
|
|
I'm just trying to wrap my head around the proper way to use an Oracle Directory with UTL_FILE.FOPEN().
I use the following code:
DECLARE
F1 UTL_FILE.FILE_TYPE;
BEGIN
F1 := UTL_FILE.FOPEN('MYDIR','MYFILE','R');
.
.
.
.
UTL_FILE.FCLOSE(F1);
END;
Another person is using this method:
DECLARE
DIRECTORY_NAME varchar2(100);
DIRECTORY_NAME := LOOKUP('MYDIR') -- this is a function that looks up MYDIR from the Oracle Directory Table and returns the Path (/var/spool/hr).
F1 UTL_FILE.FILE_TYPE;
BEGIN
F1 := UTL_FILE.FOPEN(DIRECTORY_NAME,'MYFILE','R');
.
.
.
.
UTL_FILE.FCLOSE(F1);
END;
Both methods work but the other person wants to use his LOOKUP Function to return the Path versus just using the Oracle Directory Name. We're on 12.2 and going to 19c. I feel, we should be using the actual Oracle Directory Name and not a Path when we go to 19c.
Will his method continue to work on 19c? I know mine will since it's the actual Oracle Directory Name.
[Updated on: Fri, 03 June 2022 18:47] Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: Directory Name with UTL_FILE.FOPEN() [message #686049 is a reply to message #686048] |
Sat, 04 June 2022 11:23   |
Duane
Messages: 585 Registered: December 2002
|
Senior Member |
|
|
Ok, I think I follow you.
Oracle Directory
Name Path
MYDIR /var/spool/hr
12.2 Works because of UTL_FILE_DIR
UTL_FILE.FOPEN('MYDIR','MYFILE','R');
UTL_FILE.FOPEN('/var/spool/hr','MYFILE','R');
19c Won't work because no UTL_FILE_DIR
UTL_FILE.FOPEN('/var/spool/hr','MYFILE','R');
19c Works
UTL_FILE.FOPEN('MYDIR','MYFILE','R');
Anyone have 19c to confirm? Take any Oracle Directory you have and do UTL_FILE.FOPEN('Oracle Directory','MYFILE','R'); UTL_FILE.FOPEN('Oracle Directory Path','MYFILE','R'); Only one works, both work?
|
|
|
|
|
|
|
|
|
Re: Directory Name with UTL_FILE.FOPEN() [message #686079 is a reply to message #686042] |
Wed, 08 June 2022 09:23   |
Duane
Messages: 585 Registered: December 2002
|
Senior Member |
|
|
So it appears I had the LOOKUP function wrong. I must have done the LOOKUP on the server side which returns a PATH.
On the Oracle side, the LOOKUP function just returns the Directory Name, which, doesn't make any sense to me at all.
DIRECTORY_NAME varchar2(100);
DIRECTORY_NAME := LOOKUP('MYDIR') -- this is a function that looks up MYDIR from the Oracle Directory Table and returns the Directory Name (MYDIR).
DIRECTORY_NAME := 'MYDIR'
So, the LOOKUP function takes a Directory Name and then returns that Directory Name. I'm not even sure why we even have this because it seems pointless to me. It's a function that doesn't even need to be called. Why we're even doing this is beyond me.
These are the same:
F1 := UTL_FILE.FOPEN('MY_DIR','T.TXT','R');
F1 := UTL_FILE.FOPEN(LOOKUP('MY_DIR'),'T.TXT','R');
Anyway, thanks for your help.
|
|
|
|
|
|
|
Re: Directory Name with UTL_FILE.FOPEN() [message #686086 is a reply to message #686042] |
Wed, 08 June 2022 13:36  |
Duane
Messages: 585 Registered: December 2002
|
Senior Member |
|
|
The LOOKUP function just returns what's given to it. If an Oracle Directory can't be found then it just returns the value supplied in the function.
HR := LOOKUP('HR');
MYDIR := LOOKUP('MYDIR');
ELVIS := LOOKUP('ELVIS');
DOES THIS REALLY WORK := LOOKUP('DOES THIS REALLY WORK');
|
|
|
Goto Forum:
Current Time: Fri Jul 04 01:00:58 CDT 2025
|