Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

utl_file.fseek

813348May 27 2011 — edited Apr 11 2012
Hi all,


I want to know about the procedure fseek in utl_file
I know that we can use this procedure to move back or forward in a file without closing and opening it


but what i cant get is how this works

say this is the example

declare
 name varchar2(30);
 f1 utl_file.file_type;
 pos number; 
begin
   f1 := utl_file.fopen('VIR','SEARCH.TXT','R');
   utl_file.fseek(f1,10);
  	pos := utl_file.fgetpos(f1);
 dbms_output.put_line ('SUCCESS Seek to abs offset 10, currect position is '||to_char(pos));		
   utl_file.fseek(f1,NULL,5);
       pos := utl_file.fgetpos(f1);
 dbms_output.put_line ('SUCCESS Seek to relative offset 5, currect position is'||to_char(pos));
   utl_file.fseek(f1,10,5);
       pos := utl_file.fgetpos(f1);
 dbms_output.put_line ('SUCCESS Seek to absolute 10 relative offset 5, currect position is'||to_char(pos));
   utl_file.fseek(f1,NULL,-5);
       pos := utl_file.fgetpos(f1);
 dbms_output.put_line ('SUCCESS Seek to rel offset -5, currect position is '||to_char(pos));
   utl_file.fclose(f1);
end; 
/



o/p is




SQL> /
SUCCESS Seek to abs offset 10, currect position is 10
SUCCESS Seek to relative offset 5, currect position is15
SUCCESS Seek to absolute 10 relative offset 5, currect position is10
SUCCESS Seek to rel offset -5, currect position is 5

PL/SQL procedure successfully completed.
What i dont understand is when i am using both absolute and relative offset i.e abs = 10 and rel = 5
then why its current position is 10 when i thought it would be 15?
please correct me if i am wrong.

or does it not consider the relative offset when the absolute is given

What i am thinking is when absolute and relative offset in fseek is present then the position should be

absolute + relative.

when absolute is null and relative is present the position would be


current position +/- relative offset


and if relative offset is null and absolute is present the current position is

absolute offset


thanks
This post has been answered by John Spencer on May 27 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 9 2012
Added on May 27 2011
4 comments
2,278 views