我想检索特定文件夹中所有文件的列表,其中包括 oracle 表单和菜单和报告以及一些 txt 文件...
您知道如何以 ORACLE 形式检索这些数据,并将它们自动插入到我的数据块中吗?
我使用oracle form 6.0。
我想检索特定文件夹中所有文件的列表,其中包括 oracle 表单和菜单和报告以及一些 txt 文件...
您知道如何以 ORACLE 形式检索这些数据,并将它们自动插入到我的数据块中吗?
我使用oracle form 6.0。
I did something along these lines:
Create an Oracle directory for the directory you want to list:
create or replace directory YOURDIR
as '\path\to\your\directory';
Build a temporary table:
create global temporary table DIR_LIST
(
FILENAME VARCHAR2(255),
)
on commit preserve rows;
grant select, insert, update, delete on DIR_LIST to PUBLIC;
You'll need a java stored procedure:
create or replace and compile java source named dirlist as
import java.io.*;
import java.sql.*;
import java.text.*;
public class DirList
{
public static void getList(String directory)
throws SQLException
{
File dir = new File( directory );
File[] files = dir.listFiles();
File theFile;
for(int i = 0; i < files.length; i++)
{
theFile = files[i];
#sql { INSERT INTO DIR_LIST (FILENAME)
VALUES (:theName };
}
}
}
And a PL/SQL callable procedure to invoke the java:
CREATE OR REPLACE PROCEDURE get_dir_list(pi_directory IN VARCHAR2)
AS LANGUAGE JAVA
name 'DirList.getList(java.lang.String)';
Finally, calling the procedure get_dir_list inside your form will populate the table with the files in your directory, which you can then read into your form block.
The java code came straight out of a Tom Kyte book (don't recall which one).
EDIT:
Actually, all the code is pretty much lifted from this AskTom thread.
外部表还有另一种有趣的方法,它可以更轻松地检索此类列表,而无需使用 Java 存储过程:
$ mkdir /tmp/incoming
$ cat >/tmp/incoming/readdir.sh<<eof
#/bin/bash
cd /tmp/incoming/
/bin/ls -1
eof
# test files
$ for i in {1..5}; do touch /tmp/incoming/invoice_no_$RANDOM.pdf; done
在 SQL*Plus 中:
create or replace directory incoming as '/tmp/incoming';
Directory INCOMMING created.
create table files (filename varchar2(255))
organization external (
type oracle_loader
default directory incoming
access parameters (
records delimited by newline
preprocessor incoming:'readdir.sh'
fields terminated by "|" ldrtrim
)
location ('readdir.sh')
);
/
Table FILES created.
select * from files;
FILENAME
--------------------------------------------------------------------------------
FILES_27463.log
invoice_no_20891.pdf
invoice_no_2255.pdf
invoice_no_24086.pdf
invoice_no_30372.pdf
invoice_no_8340.pdf
readdir.sh
7 rows selected
这种方法是在@DCookie 的回答中提到的同一个Ask Tom 线程中添加的。