Home » SQL & PL/SQL » SQL & PL/SQL » UTL_FILE.fgetattr issue
UTL_FILE.fgetattr issue [message #155156] Thu, 12 January 2006 11:26 Go to next message
buck444
Messages: 80
Registered: January 2006
Location: Luxembourg
Member
Hi,

i'm struggling with UTL_FILE.fgetattr. Why is the following code returns: "file doesnt exist" as soon as i'm using the variable "date_convert" instead of the file name directly?

DECLARE
  ex           BOOLEAN;
  file_length  NUMBER;
  blsize       NUMBER;
  date_convert char(250);
  test         char(250);
BEGIN
  date_convert := 'ABC_TEST_' ||
                  to_char(sysdate - 1, '""YYYY-""MM-""DD".csv"');
  test         := 'ABC_TEST_2006-01-11.csv';
  DBMS_OUTPUT.PUT_LINE(date_convert); --shows filename
  DBMS_OUTPUT.PUT_LINE(test); --shows filename
  utl_file.fgetattr('ETL_FOLDER1',
                    date_convert,
                    ex,
                    file_length,
                    blsize);
  IF ex THEN
    dbms_output.put_line('File Exists');
  ELSE
    dbms_output.put_line('File Does Not Exist');
  END IF;
  dbms_output.put_line('File Length: ' || TO_CHAR(file_length));
  dbms_output.put_line('Block Size: ' || TO_CHAR(blsize));
END;
/


I did the same thing with UTL_FILE.fopen and that's working fine!
Of course a have the file in the correct folder and i did create the directory object correct. It is working, if i'm using the filename directly.

Oracle: 9.2.0.1
OS: Win XP
Re: UTL_FILE.fgetattr issue [message #155163 is a reply to message #155156] Thu, 12 January 2006 12:01 Go to previous messageGo to next message
Frank
Messages: 7901
Registered: March 2000
Senior Member
Why do you use all them quotes around the date-format?
Your code looks ok to me.
If you change the date_convert to test it works?

[Updated on: Thu, 12 January 2006 12:02]

Report message to a moderator

Re: UTL_FILE.fgetattr issue [message #155168 is a reply to message #155156] Thu, 12 January 2006 12:29 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Use VARCHAR2 for the date_convert variable instead of CHAR. The FOPEN and FGETATTR methods do not work with a CHAR variable (I realize you said the FOPEN worked for you, but check it again - it does not for me).
Re: UTL_FILE.fgetattr issue [message #155262 is a reply to message #155156] Fri, 13 January 2006 07:06 Go to previous messageGo to next message
buck444
Messages: 80
Registered: January 2006
Location: Luxembourg
Member
Hi,

i've found the error. it was the value of char for the variable "convert_date".

date_convert char(250);


With a value <228 it's working fine.

Frank:
I tried a bit with the conversion from the date. In the Database it is save as DD-MON-YYYY. But the filename is: DD-MM-YYYY. So, i have to convert the date (sysdate) to the filename format.

Do you know another way or do you have a nice link which can point me to a more efficient code? I am also thinking, that it's unusual to have to use so many quotes, but it's only working (up to now) with this construct.



Re: UTL_FILE.fgetattr issue [message #155302 is a reply to message #155262] Fri, 13 January 2006 12:24 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
On 9.2.0.7, I cannot use a CHAR variable where the defined length is greater than the actual filename (because of the space padding).

sql>declare 
  2    v_filename  char(30) := 'test.txt'; 
  3    f  utl_file.file_type; 
  4  begin 
  5    f := utl_file.fopen('FILES', v_filename, 'r'); 
  6    utl_file.fclose(f); 
  7  end;
  8  /
declare
*
ERROR at line 1:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 449
ORA-29283: invalid file operation
ORA-06512: at line 5

sql>declare 
  2    v_filename  varchar2(30) := 'test.txt'; 
  3    f  utl_file.file_type; 
  4  begin 
  5    f := utl_file.fopen('FILES', v_filename, 'r'); 
  6    utl_file.fclose(f); 
  7  end;
  8  /

PL/SQL procedure successfully completed.


How is this (using a CHAR variable, even with a reduced size) working for you? A 9.2.0.1 oddity?

More importantly, why even use a CHAR here? It is not the datatype that UTL_FILE is expecting. There is absolutely no reason to use it here in place of VARCHAR2.
Re: UTL_FILE.fgetattr issue [message #155557 is a reply to message #155156] Tue, 17 January 2006 04:08 Go to previous messageGo to next message
buck444
Messages: 80
Registered: January 2006
Location: Luxembourg
Member
The Procedure is created succesfully with 9.2.0.1 and a CHAR Variable!

I changed the format to VARCHAR2 anyway, because it seems that this kind of type is better for Win XP. (At least a few people told me that, and it's working).

[Updated on: Tue, 17 January 2006 04:13]

Report message to a moderator

Re: UTL_FILE.fgetattr issue [message #155654 is a reply to message #155557] Tue, 17 January 2006 16:37 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Yes, the procedure will be created if you use a CHAR datatype, but this is a runtime error issue.
Previous Topic: HELP Fast!! Changes in the DDL from 8i to 9i
Next Topic: retrieving distinct values and ordering the results
Goto Forum:
  


Current Time: Sun Aug 24 09:35:13 CDT 2025