Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access file system to copy files

Status
Not open for further replies.

lecorr

Programmer
Apr 9, 2003
62
FR
Hi,

Does any one of you know how to copy, delete, create files in OS filesystem directly from oracle?

UTL_FILE is no help for my use...

Thanks,

Christian
 
You may create simple java wrapper for OS commands and call them from pl/sql.

Regards, Dima
 
assuming UNIX (as you do not say which OS)

use a host command from sqlplus

Note the '!'

SQL> ! cp file file2

Alex
 
Thank you both,

I need this to be used from DB triggers (and MS Windows).

Sem, do you have a sample?

Thanks again for your answers...

Christian
 
create or replace and compile java source named util as
import java.io.*;
import java.lang.*;
public class Util extends Object
{
public static int RunThis(String[] args)
{
Runtime rt = Runtime.getRuntime();
int rc = -1;
try
{
Process p = rt.exec(args[0]);
int bufSize = 4096;
BufferedInputStream bis =
new BufferedInputStream(p.getInputStream(), bufSize);
int len;
byte buffer[] = new byte[bufSize];
// Echo back what the program spit out
while ((len = bis.read(buffer, 0, bufSize)) != -1)
System.out.write(buffer, 0, len);
rc = p.waitFor();
}
catch (Exception e)
{
e.printStackTrace();
rc = -1;
}
finally
{
return rc;
}
}
}
/
create or replace function RUN_CMD( p_cmd in varchar2) return number
as
language java
name 'Util.RunThis(java.lang.String[]) return integer';
/

You should also grant some rights by SYS:

exec dbms_java.grant_permission(<user>, 'java.io.FilePermission', <pathe to executable>,
'execute');

and probably (not sure) rights to read/write to specific directories:
Code:
exec dbms_java.grant_permission(<user>,  'java.lang.RuntimePermission', <path to file>, 'writeFileDescriptor' )

exec dbms_java.grant_permission(<user>,  'java.lang.RuntimePermission', <path to file>, 'readFileDescriptor' )

exec dbms_java.grant_permission(<user>,  'java.io.FilePermission', <path to file>,'read,write');

Regards, Dima
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top