|
|
|
|
|
|
|
Re: Is it possible to insert a folder from a directory into a table? [message #677009 is a reply to message #677007] |
Tue, 06 August 2019 13:30   |
 |
Bartholomew Kuma
Messages: 12 Registered: March 2019
|
Junior Member |
|
|
BlackSwan wrote on Tue, 06 August 2019 12:36FWIW - if you are changing the actual content of the ZIP file by including "random" CHR(10) values,
the BLOB most likely will fail to unzip & reproduce the original contents.
You really need to verify that you can unzip the stored BLOB content & actually extract the original directory content.
The first step I want to achieve is to be able to specifically insert the folder into the table, not just the contents of the folder.
I tried with this code:
DECLARE
oNew BLOB;
oBFile BFILE;
v_path varchar2(100) :='TOKS_HR_DIR_EXT_HDL';
v_fileName varchar2(4000) := '';
BEGIN
oBFile := BFILENAME(v_path,null);
DBMS_LOB.OPEN(oBFile, DBMS_LOB.LOB_READONLY);
DBMS_LOB.createtemporary(oNew,TRUE);
DBMS_LOB.LOADFROMFILE(oNew, oBFile, dbms_lob.lobmaxsize);
DBMS_LOB.CLOSE(oBFile);
INSERT INTO TOKS_HR_ARCHIVOS2 VALUES ( oNew );
dbms_lob.freetemporary(oNew);
END;
but it throws the following errors:
ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275
ORA-06512: at "SYS.DBMS_LOB", line 1014
ORA-06512: at line 8
Thanks
|
|
|
|
|
Re: Is it possible to insert a folder from a directory into a table? [message #677013 is a reply to message #677012] |
Wed, 07 August 2019 12:21   |
 |
Michel Cadot
Messages: 68417 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
You can get a file list using the following undocumented procedure (if you have access to SYS to create it):
SYS> CREATE OR REPLACE PROCEDURE get_file_list (p_files VARCHAR2)
2 IS
3 l_null varchar2(100) := NULL;
4 l_files varchar2(100);
5 BEGIN
6 l_files := p_files;
7 sys.dbms_backup_restore.searchfiles(l_files, l_null);
8 FOR x IN (select fname_krbmsft fname from x$krbmsft) LOOP
9 dbms_output.put_line(x.fname);
10 END LOOP;
11 END;
12 /
Procedure created.
SYS> GRANT execute ON get_file_list TO Michel
2 /
Grant succeeded.
SYS> conn michel/michel
Connected.
MICHEL> exec sys.get_file_list ('C:\TEMP\*.JPG')
C:\TEMP\Travel1.JPG
C:\TEMP\Travel2.JPG
C:\TEMP\Travel3.JPG
C:\TEMP\Travel4.JPG
C:\TEMP\Travel5.JPG
PL/SQL procedure successfully completed.
Now you can compress them in a single ZIP file using the very useful Anton Scheffer's as_zip package.
(Read the terms of use.)
[Updated on: Wed, 07 August 2019 12:25] Report message to a moderator
|
|
|
Re: Is it possible to insert a folder from a directory into a table? [message #677019 is a reply to message #677013] |
Wed, 07 August 2019 13:24   |
 |
Michel Cadot
Messages: 68417 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Another way to get the list of the files is to use an external table with a preprocess step:
SQL> CREATE OR REPLACE DIRECTORY temp_dir AS 'C:\TEMP';
Directory created.
SQL> CREATE TABLE files (
2 file_date VARCHAR2(15),
3 file_time VARCHAR2(15),
4 file_size VARCHAR2(15),
5 file_name VARCHAR2(50)
6 )
7 ORGANIZATION EXTERNAL (
8 TYPE ORACLE_LOADER
9 DEFAULT DIRECTORY temp_dir
10 ACCESS PARAMETERS (
11 RECORDS DELIMITED BY NEWLINE
12 NOBADFILE
13 NOLOGFILE
14 PREPROCESSOR temp_dir:'list_files.bat'
15 FIELDS TERMINATED BY WHITESPACE
16 )
17 LOCATION ('files.lst')
18 )
19 REJECT LIMIT UNLIMITED
20 /
Table created.
The "list_files.bat" script just lists the desired files:
SQL> host type c:\temp\list_files.bat
@echo off
dir %~dp0\*.JPG
So to get the list you just have to query the table:
SQL> SELECT * FROM files WHERE file_name LIKE '%.JPG';
FILE_DATE FILE_TIME FILE_SIZE FILE_NAME
--------------- --------------- --------------- --------------------------------------------------
02/04/2004 12:07 258ÿ767 Travel1.JPG
23/08/2004 17:55 374ÿ382 Travel2.JPG
23/08/2004 17:56 311ÿ217 Travel3.JPG
23/08/2004 17:56 201ÿ726 Travel4.JPG
23/08/2004 17:57 269ÿ047 Travel5.JPG
5 rows selected.
"files.lst" does not matter, it is just there for the need of the CREATE TABLE syntax.
In my example, JPG files, location file and script are in the same directory, this may not be your case, you have to change the access parameters and the bat script. In the same way, if you are on Linux/Unix you obviously have to change the shell script.
|
|
|
|