Good Morning:
Online I learned a way to be able to query my oracle directory by utilizing the following:
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "FileListHandler" AS
import java.lang.*;
import java.util.*;
import java.io.*;
public class FileListHandler
{
public static String list (String path) {
String list = "";
File myFile = new File (path);
String[] arrayList = myFile.list();
Arrays.sort(arrayList, String.CASE_INSENSITIVE_ORDER);
for (int i=0; i < arrayList.length; i++) {
// Prevent directory listing expanding if we will blow VARCHAR2 limit.
if ((list.length() + arrayList[i].length() + 1) > 32767)
break;
if (!list.equals(""))
list += "," + arrayList[i];
else
list += arrayList[i];
}
return list;
}
};
/
show errors java source "FileListHandler"
CREATE OR REPLACE PACKAGE file_list_api AS
FUNCTION list (p_path IN VARCHAR2) RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'FileListHandler.list (java.lang.String) return java.lang.String';
END file_list_api;
/
SHOW ERRORS
CREATE OR REPLACE TYPE t_varchar2_arr AS TABLE OF VARCHAR2(500);
/
CREATE OR REPLACE FUNCTION get_files (p_dir IN VARCHAR2)
RETURN t_varchar2_arr PIPELINED
AS
l_array APEX_APPLICATION_GLOBAL.vc_arr2;
l_string VARCHAR2(32767);
BEGIN
l_array:= APEX_STRING.string_to_table(FILE_LIST_API.list(p_dir), ',');
FOR i in 1..l_array.count LOOP
PIPE ROW(l_array(i));
END LOOP;
RETURN;
END;
/
However, there is a limitation on the amount of files it reads just based upon the varchar2 limitation. Is there anyway to adjust the above code so that it reads the entire directory?
I did read online that this methodology of reading a directory is somewhat outdated, and that external tables should be utilized. I tried following examples but I could not get it to work.
Any help would be greatly appreciated and thanks!
Aqua