Requirement: How to find the list of files in specified directory?
Step1 : First find the JDK Install or not in the oracle, to find jdk version please run the below sql.
SELECT dbms_java.get_ojvm_property(PROPSTRING=>'java.version') FROM dual
Step2: Once get the output above then only we can create the java source. If the output is diaplyed then perform the below task
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "list_of_files" AS
import java.io.File;
public class list_of_files {
public static String getFileList(String idir)
// public static void main(String[] args)
{
//System.out.println("testing");
File aDirectory = new File(idir);
File[] filesInDir = aDirectory.listFiles();
String result = "";
for ( int i=0; i<filesInDir.length; i++ )
{
if ( filesInDir[i].isFile()
&& !filesInDir[i].isHidden() )
{
result = result + "," +filesInDir[i].getName();
System.out.println("result="+result);
}
}
return result;
}
}
--------------------------------
Compile the above code.
3. create or replace function test_fun(p_dir varchar2) return varchar2
AS LANGUAGE JAVA NAME
'list_of_files.getFileList(java.lang.String) return String';
----------------
Compile the above code
4.select test_fun('c:\jars') from dual;
run the above sql command.