Home » SQL & PL/SQL » SQL & PL/SQL » to parse a file name
to parse a file name [message #222586] Mon, 05 March 2007 09:40 Go to next message
AGARWALNIRU
Messages: 13
Registered: March 2007
Junior Member
hi

I have to pull out the name of a PDF file from a content folder and parse the name as it has information in the name which i have to further store in a flat file. I am trying to do this thru procedure in PL/SQL . can anybody provide the code .........plz help!!!!
Re: to parse a file name [message #222589 is a reply to message #222586] Mon, 05 March 2007 09:59 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
You'll need something in Java or C (or in fact anything outside Pl/Sql) to get a list of the files.
I can't think of a way of doing that in Pl/Sql, except possibly itterating throught every possible file name and trying to open it with UTL_FILE.
Re: to parse a file name [message #222601 is a reply to message #222589] Mon, 05 March 2007 10:37 Go to previous messageGo to next message
AGARWALNIRU
Messages: 13
Registered: March 2007
Junior Member
thanks!!
I know this is to much to ask, but can u please give me some information to ho wo do that , maybe in Java or Perl

Sad I need this urgently.
Re: to parse a file name [message #222674 is a reply to message #222601] Mon, 05 March 2007 21:36 Go to previous message
ebrian
Messages: 2794
Registered: April 2006
Senior Member
If you are on 10g, you can consider using the following procedure:

SQL> host dir e:\files
 Volume in drive E is Data
 Volume Serial Number is 287D-3237

 Directory of e:\files

03/05/2007  10:32 PM    <DIR>          .
03/05/2007  10:32 PM    <DIR>          ..
05/17/2006  06:36 PM         1,369,430 file1.pdf
12/11/2006  07:03 PM         1,812,413 file2.pdf
05/10/2006  05:48 PM         4,136,752 file3.txt
05/10/2006  05:48 PM         4,136,752 file4.pdf
12/16/2006  09:49 AM         1,732,255 file5.pdf
05/10/2006  05:48 PM         4,136,752 file7.txt
               6 File(s)     17,324,354 bytes
               2 Dir(s)  14,188,064,768 bytes free

SQL> create or replace procedure get_dir_list
  2  (p_directory varchar2)
  3  is
  4      l_null      varchar2(100);
  5      l_directory varchar2(100);
  6  BEGIN
  7       l_directory := p_directory;
  8       sys.dbms_backup_restore.searchfiles(l_directory, l_null);
  9  FOR x IN (select fname_krbmsft fname from x$krbmsft) LOOP
 10       dbms_output.put_line(x.fname);
 11  END LOOP;
 12
 13  END;
 14  /

Procedure created.

SQL> exec get_dir_list('e:\files\*.pdf');
E:\FILES\file1.pdf
E:\FILES\file2.pdf
E:\FILES\file4.pdf
E:\FILES\file5.pdf

PL/SQL procedure successfully completed.

SQL>

This is an undocumented procedure and therefore may not be guaranteed to be in future releases, so use it at your peril.

Aside from the process above, another option would be to use Java to obtain a listing. Check here for details.
Previous Topic: INSERT INTO with multiple (!) VALUES possible ?
Next Topic: characters and numeric count in a String
Goto Forum:
  


Current Time: Thu Dec 08 21:57:18 CST 2016

Total time taken to generate the page: 0.08700 seconds