Calling OS commands from PL/SQL
I want to write a PL/SQL procedure against an Oracle 9i database to import/export data from / to a file into / from a table. I need some advice for this. Please help me out.
Any advice would be most welcome.
Cheers
SrihariKrishna Donepudi
Not to mention SQL*Loader.
Cheers, APC
Similar Messages
-
Calling UNIX command from PL/SQL Procedure
Is there a way to call a UNIX command (exa. ls) from within a PL/SQL stored procedure? Looking through the various packages, I didn't see anything that would give me this ability.
I also looked through all the previous questions and nothing looked encouraging.
Thanks in advance,
RussRuss,
I thought I'd read a similar question awhile ago and did a search on the word host in this forum and found the following from July 9th that might help you:
http://technet.oracle.com:89/ubb/Forum88/HTML/001611.html
In that post I think the link listed by Barbara Boehmer in has changed to:
]http://asktom.oracle.com/pls/ask/f?p=4950:8:24579::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:16212348050,{host}
It looks like they give solutions for Oracle 7, 8 and 8i.
Good site Barbara, I've added it to my bookmarks.
Hope this helps. -
Call OS command from PL/SQL
Hi expert,
I am using 10gDB on Linux , I have found many website desribe above mention topic. and suggest few method as below : -
1) DBMS_PIPE
2) PRO/C
3) JAVA
4) DBMS_SCHEDULER
In fact , My major execute OS command as below : -
1) copy file to another directory.
2) remove file in directory.
3) call some tools to manipulate file.
4) send email by command line.
Could u let me know which method is best ? because some command may not
execute success by each method.
borisI'm not sure what you mean by
"besides, u have't seen stability issues with either approach. how to do ??? dead la.
i think every DBA in the world also face this problem ."
Particularly the sentence
"how to do ??? dead la."
I think you are asking how to do something that you refer to as "dead la", but I can't figure out what "dead la" might mean. Is that an abbreviation for something? Or am I misunderstanding what you are trying to say?
Justin -
Calling Linux Command From Pl/SQL
Hi!
I need to create a trigger which will call a linux command. Basically, when a value changes in a table, I would like to run a linux script. The value in the table can change anytime during any day. I had a look at DBMS_JOB.SUBMIT but I'm not sure if this will work for me because I only need to run the linux script once - when the trigger is fired. I also don't wanna clutter the job queue. Please help. Thanx in advance.You didn't mention if you're looking for synchronous or asynchronous execution of your Linux command. Should the program wait for it to complete?
If it has to be synchronous, you'll need to look into using the external program listener. If asynchronous is ok (and it usually is) and then I'd go with scheduling a job - don't worry about "cluttering up the job queue".
If you're on 10g or later, don't bother with DBMS_JOB - use DBMS_SCHEDULER instead, which makes it much easier to execute an external process. -
Calling Operating System Commands from PL/SQL using java
Calling Operating System Commands from PL/SQL - The Java Way
wlth help of given thread link,
Calling OS Commands from Plsql
but i had user privilege problem
Declare
x Varchar2(2000);
Begin
x := OSCommand_Run('/tmp/sri/GROUP_ho.sh');
DBMS_OUTPUT.Put_Line(x);
End;
o/p;
can't exec: /tmp/sri/GROUP_ho.sh lacks user privilege
i done the grant privillage also
part
dbms_java.grant_permission('abcd', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
dbms_java.grant_permission('abcd', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
dbms_java.grant_permission('
abcd', 'SYS:java.io.FilePermission','<<ALL FILES>>', 'execute');
again
get
can't exec: /tmp/sri/GROUP_ho.sh lacks user privilege
same error;Process management at the OS level should prevent execution continuing in the calling code until the command has completed (either successfully or with error).
If the low level java code were to spawn child process threads then execution could continue, but I'm guessing the Java function your talking about doesn't do that and just calls the operating system to execute the command and waits for the returning code to come back. -
How to: execute operating system commands from PL/SQL
System: IBM pSeries AIX
Oracle: 11g Enterprise
Is there a quick way to execute operating system commands from PL/SQL?
Without creating a JAVA class....
I need to execute a Loader script.
I want to do this from within PL/SQL.
I need to to do 4 things.
Three require SQL scripts.
The fourth is SQL*Loader.
The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
Is there way to do all this from within ONE PL/SQL SCRIPT ??
Just let me know.Is there a quick way to execute operating system commands from PL/SQL?
NO
Without creating a JAVA class....
I need to execute a Loader script.
I want to do this from within PL/SQL.
WHY ON EARTH, such action will create a new connection and become a resource hog?
I need to to do 4 things.
Three require SQL scripts.
The fourth is SQL*Loader.
The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
Which is perfect for the purpose.
Is there way to do all this from within ONE PL/SQL SCRIPT ??
Just let me know.
NO, there is NOT. Nor should there be. Why create unstable ineffcient Mickey Mouse systems, glued together by hacking?
Sybrand Bakker
Senior Oracle DBA -
Calling Cobol program from PL/SQL
What is the caling convention for PL/SQL to call a Cobol program?
You cannot do it directly from PL/SQL. PL/SQL is.. well, kind of abstract ito the actual platform it runs on. PL/SQL cannot talk directly to operating system. It cannot (itself) do socket calls, file I/O calls, use the printer, etc.
<p>
All this has to be done using a lower level implementation library - like UTL_FILE for example that wraps internal C written modules that does file I/O. PL/SQL can call these to do I/O on its behalf. Ditto for wrappers like UTL_TCP and others.
<p>
There is no default wrapper for calling external processes from PL/SQL. It can however be done indirectly using the external procedure (EXTPROC) feature, or using Java to do it.
<p>
The latter is the easiest. You create a Java stored proc that can access the operating system and run external programs and commands. You punch a big hole in the Oracle Java security to allow this Java stored proc access to the operating system. Next you create a PL/SQL wrapper for this Java proc which then in turn can be called from PL/SQL.
Just remember that you MUST secure this hole you've punched into Oracle security. If any Oracle user can access this PL/SQL wrapper, they can hack, compromise, trash or simply destroy your entire Oracle account on that server.
Here is the basic code:
create or replace and compile Java Source named "OSCommand" as
-- java: OS COMMAND
-- descr: Executes an Operating System Command using the JAVA RTS
-- IN parameter: os command to execute (including fully qualified path names)
-- OUT parameter: returncode [\nstring]
-- where string a max of 32000 chars of the output of the command
-- (note that \n is used as separators in the string)
-- returncode=-1 Java RTS error occurred (e.g. command does not exist)
-- returncode=255 o/s command failed (e.g. invalid command params)
import java.io.*;
import java.lang.*;
public class OSCommand{
public static String Run(String Command){
Runtime rt = Runtime.getRuntime();
int rc = -1;
try{
Process p = rt.exec( Command );
int bufSize = 32000;
int len = 0;
byte buffer[] = new byte[bufSize];
String s = null;
BufferedInputStream bis = new BufferedInputStream( p.getInputStream(), bufSize );
len = bis.read( buffer, 0, bufSize );
rc = p.waitFor();
if ( len != -1 ){
s = new String( buffer, 0, len );
return( s );
return( rc+"" );
catch (Exception e){
e.printStackTrace();
return( "-1\ncommand[" + Command + "]\n" + e.getMessage() );
show errors
create or replace function OSexec( cCommand IN string ) return varchar2 is
-- function: OS EXEC
-- descr: PL/SQL wrapper for the Java OSCOMMAND stored proc
language JAVA
name 'OSCommand.Run(java.lang.String) return java.lang.String';
show errors
-- Punching a hole into the Java VM sandbox. The following must be run as
-- sysdba. Substitute SCOTT with the applicable schema that owns the OSEXEC
-- and OSCOMMAND stored procs.
declare
SCHEMA varchar2(30) := 'SCOTT';
begin
dbms_java.grant_permission(
SCHEMA,
'SYS:java.io.FilePermission',
'<<ALL FILES>>',
'execute'
dbms_java.grant_permission(
SCHEMA,
'SYS:java.lang.RuntimePermission',
'writeFileDescriptor',
dbms_java.grant_permission(
SCHEMA,
'SYS:java.lang.RuntimePermission',
'readFileDescriptor',
commit;
end;
-- example: running the Unix/Linux date command to get the current date and time
SQL> select OSexec('/usr/bin/date') as STDOUT from dual;
STDOUT
Fri Sep 1 08:09:34 SAST 2006
1 row selected.
SQL>Edited by: Billy Verreynne on Sep 4, 2008 6:26 PM to make the code snippet readable with the new Jive forum s/w. -
How to call OS Commands through PL/SQL ?
Is there any package to call OS (Solaris) commands from PL/SQL ? I want to do who cammand within PL/SQl Stored Proc and get the output inserted into a table. How can I do this ?
Why don't you want to use Java? There are certainly alternatives, but without knowing why you don't like the Java solution, it's rather hard to know whether those alternatives make any sense in your environment.
- You can make an external procedure call to a DLL (or shared library) installed on the server
- You could use AQ or potentially DBMS_PIPE to communicate with external applications
- You could use UTL_TCP to interact over the network with a machine
- You may have other options depending on specifics about the call you're trying to make and the software you have.
- In 10g, you could use the DBMS_SCHEDULER package to call OS commands
Justin -
O/s commands from PL/SQL
hi all..
i want to execute operating system commands from PL/SQL..
particulary imp command....
i have used the f/wg approach but while i execute the imp command it does not responds me any output..
I have to kill the process from o/s.
prodn is my user
--AS SYS user
begin
dbms_java.grant_permission( 'PRODN',
'SYS:java.io.FilePermission',
'/oracle/product/9.2.0/bin/imp',
'execute' );
dbms_java.grant_permission
('PRODN',
'java.lang.RuntimePermission',
'writeFileDescriptor' );
end;
---------------------------------AS PRODN user
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);
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';
create or replace procedure RC(p_cmd in varchar2)
as
x number;
begin
x := run_cmd(p_cmd);
end;
i executed the command as follows in sql>
BEGIN
rc('/oracle/product/9.2.0/bin/imp tim/tim file=/home/oracle/vas4359.dmp log
=log1.log');
END;
it runs fine creates log1.log in / home/oracle but there is no output in
log1.log file.
I have to kill the process as follows after which sql> displays me :
"PL/SQL procedure successfully completed."
[oracle@msebdb oracle]$ ps aux|grep imp
oracle 20052 0.0 0.2 12732 4328 ? S 11:57 0:00 /oracle/product/
.2.0/bin/imp file=/home/oracle/vas4359.dmp log=log1.log
oracle 20102 0.0 0.0 3692 652 pts/2 S 12:03 0:00 grep imp
Note:There is no tim user.. i just want to get error in my log file..
my further steps are to read this log file and send email/notifications to users.
my main program is as f/ws:
/*imp and check log file*/
create or replace procedure abc
as
v_exists boolean;
v_exists_log boolean;
ex_open BOOLEAN;
flen NUMBER;
bsize NUMBER;
vInHandle_open utl_file.file_type;
vInHandle_open_log utl_file.file_type;
v_filelog utl_file.file_type;
v_fl utl_file.file_type;
v_pth varchar2(60);
v_fnm varchar2(60);
v_file_exists varchar2(60);
v_logline varchar2(30) ;
v_search varchar2(30) :='ORA-';
vNewLine VARCHAR2(32767);
cursor c_fname is
select full_pth ,f_name from upld_file_t where f_name in
(select f_name from tbl_file_nm where typ_file='D' AND DEL_FLG='N');
BEGIN
for v_sec in c_fname
loop
utl_file.fgetattr(LOCATION=>'ORALOAD',
FILENAME=>v_sec.f_name,
FEXISTS=>v_exists,
FILE_LENGTH=> flen,
BLOCK_SIZE=>bsize);
if v_exists
THEN
dbms_output.put_line('File Exists' || v_sec.f_name);
v_file_exists:=v_sec.f_name;
--dbms_output.put_line('v_file_exists ' || v_file_exists);
dbms_output.put_line('File Length: ' || TO_CHAR(flen));
dbms_output.put_line('Block Size: ' || TO_CHAR(bsize));
dbms_output.put_line(' before file open');
vInHandle_open := utl_file.fopen('ORALOAD',v_sec.f_name,'R',32767);
-- dbms_output.put_line(' after file open');
-- do whater with teh file data
v_fl:=utl_file.fopen('ORALOAD','v_sec.f_name','W');
dbms_output.put_line('v_sec.f_name');
IF utl_file.is_open(vInHandle_open)
THEN
/*if log file exists..*/
utl_file.fgetattr(LOCATION=>'ORALOAD',
FILENAME=>v_sec.f_name||'.log',
FEXISTS=>v_exists_log,
FILE_LENGTH=> flen,
BLOCK_SIZE=>bsize);
if v_exists_log
then
dbms_output.put_line('file' ||v_sec.f_name||'.log');
v_filelog :=utl_file.fopen('ORALOAD',v_sec.f_name||'.log','W',32767);
LOOP
BEGIN
UTL_FILE.PUT(v_filelog,'ORA-');
exit;
END;
END LOOP;
else
dbms_output.put_line('File not found' || v_sec.f_name);
END IF;
UTL_FILE.fclose(v_filelog);
dbms_output.put_line('Closed File ' || v_sec.f_name|| '.log');
END IF;
/*imp THE FILE and read log file*/
utl_file.fgetattr(LOCATION=>'ORALOAD',
FILENAME=>v_sec.f_name||'.log',
FEXISTS=>v_exists_log,
FILE_LENGTH=> flen,
BLOCK_SIZE=>bsize);
if v_exists_log
then
dbms_output.put_line('file' ||v_sec.f_name||'.log');
v_filelog :=utl_file.fopen('ORALOAD',v_sec.f_name||'.log','R',32767);
LOOP
BEGIN
UTL_FILE.get_line(v_filelog,v_logline);
if v_logline = v_search then
dbms_output.put_line(v_logline);
end if;
UTL_FILE.fclose(v_filelog);
dbms_output.put_line('Closed File ' || v_sec.f_name|| '.log');
exit;
END;
END LOOP;
else
dbms_output.put_line('File not found' || v_sec.f_name);
END IF;
END IF;
END LOOP;
--close the curosr .. check this
EXCEPTION
WHEN UTL_FILE.ACCESS_DENIED THEN
DBMS_OUTPUT.PUT_LINE('No Access!!!');
when others then
dbms_output.put_line('ERROR (open_file) => '||sqlcode);
dbms_output.put_line('MSG (open_file) => '||sqlerrm);
end;Hi,
You might have better luck in the PL/SQL or Java forums. They are located here:
PL/SQL: PL/SQL
Java: http://forums.oracle.com/forums/forum.jsp?forum=99
Good luck,
Mark -
Calling a report from pl/sql
Is it possible to call a report from pl/sql. I want to create a package which when invoked by dbms_jobs will create parameters and then call a report.
Thanks in advance,
Mark.Mark,
cf: http://download-uk.oracle.com/docs/cd/B10464_05/bi.904/b13673/pbr_evnt.htm#sthref1477
Patrick. -
How to call javascript function from PL/SQL procedure
Can anybody advice me how to call javascript function from PL/SQL procedure in APEX?
Hi,
I have a requirement to call Javascript function inside a After Submit Process.
clear requirement below:
1. User selects set of check boxes [ say user want to save 10 files and ticks 10 checkboxes]
2. user clicks on "save files" button
3. Inside a After submit process, in a loop, i want to call a javascript function for each of the file user want to save with the filename as a parameter.
Hope this clarify U.
Krishna. -
Run OS command from Pl/SQL
Is there any way to execute an OS command from pl/sql other than using dbms_pipe & pro*C combo. I have done this way before but it seems there is built-in oracle package which can do this in 8/8i.
Also HOST command in forms will execute the OS coomand from the clinet. Is there any way to execute the OS command on the server from the forms clinet?
thanks,
Ravi.
nullRavi,
Can you send me an example how one can
execute a this command from a PL/SQL
program 'sed 3q /etc/passwd'.
Please write to me at
[email protected]
thanks
Pramod -
Can I call a report from pl/sql?
How can I call a report from pl/sql? I would like the output to be pdf and have it outputted to the screen?
We are running Oracle 10g database and 10.1.2.3 application server on LInux Redhat 4.
Thanks.
Shirley
Edited by: jonesfnalgov on Jul 12, 2011 2:17 PM
Edited by: jonesfnalgov on Jul 12, 2011 2:18 PMHello,
a package is provided : srwAPIins.sql installs the Event-Driven Publishing API.
http://download.oracle.com/docs/cd/B14099_17/bi.1012/b14048/pbr_evnt.htm
The Event-Driven Publishing API is a PL/SQL package that provides the basic functions required for the development of procedures that respond to events in the database. Event-driven jobs are submitted using the HTTP protocol. The server assigns a unique job_ident record to every call, useful for tracking the status of the job.
Regards -
How to call web services from PL/SQL?
Hi,
Can one help in how to call web services from PL/SQL? Steps, pros and cons, etc....
Thanks in advanceHere's some example skeleton code to get you started...
PROCEDURE p_soap_request(p_username IN VARCHAR2, p_password IN VARCHAR2, p_proxy IN VARCHAR2) IS
soap_request VARCHAR2(30000);
soap_respond CLOB;
http_req utl_http.req;
http_resp utl_http.resp;
resp XMLType;
soap_err exception;
v_code VARCHAR2(200);
v_msg VARCHAR2(1800);
v_len number;
v_txt Varchar2(32767);
BEGIN
UTL_HTTP.SET_PROXY(p_proxy);
-- Define the SOAP request according the the definition of the web service being called
soap_request:= '<?xml version = "1.0" encoding = "UTF-8"?>'||
'<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">'||
' <SOAP-ENV:Body>'||
' <m:DownloadRequest xmlns:m="http://www.website.net/messages/GetDetails">'||
' <m:UserName>'||p_username||'</m:UserName>'||
' <m:Password>'||p_password||'</m:Password>'||
' </m:DownloadRequest>'||
' </SOAP-ENV:Body>'||
'</SOAP-ENV:Envelope>';
http_req:= utl_http.begin_request
( 'http://www.website.net/webservices/GetDetailsService.asmx'
, 'POST'
, 'HTTP/1.1'
utl_http.set_header(http_req, 'Content-Type', 'text/xml');
utl_http.set_header(http_req, 'Content-Length', length(soap_request));
utl_http.set_header(http_req, 'Download', ''); -- header requirements of particular web service
utl_http.write_text(http_req, soap_request);
http_resp:= utl_http.get_response(http_req);
utl_http.get_header_by_name(http_resp, 'Content-Length', v_len, 1); -- Obtain the length of the response
FOR i in 1..CEIL(v_len/32767) -- obtain response in 32K blocks just in case it is greater than 32K
LOOP
utl_http.read_text(http_resp, v_txt, case when i < CEIL(v_len/32767) then 32767 else mod(v_len,32767) end);
soap_respond := soap_respond || v_txt; -- build up CLOB
END LOOP;
utl_http.end_response(http_resp);
resp:= XMLType.createXML(soap_respond); -- Convert CLOB to XMLTYPE
END;Using secure web services (https)...
Web serivces call in Plsql
As for 'pros and cons'... there's nothing to compare against... either you want to call a web service or you don't. -
Call Oracle form from pl/sql
Dear All
How can I call Oracle form from pl/sql and open this form to end user
many thanksHshihadah wrote:
how can I show this form to specific client ?What client?!? Database PL/SQL is executed within a process on the database server, it's not something which is executed on the client. Could you please elaborate a little bit more?
By now I have not the faintest clue if you want to
- call a form from another form ( call_form )
- call a form within a database process (?!?)
- call your form from a client you did not tell us (probably APEX?!?)
For the case you really meant to call a form within Database PL/SQL: Just in case you didn't recognize it, but the database is perfectly capable of PL/SQL and as calling a form within a database process is a one-way street as you cannot interact with it there is no point at all in writing the things you want to do in forms. If you want some PL/SQL code executed on the database then...well...put it in a stored procedure in the database!
cheers
Maybe you are looking for
-
Loop Playback enabled or disabled at a glance?
Can't find the way to understand at a glance if Loop Playback is enabled or disabled. Is it possible that FCPX lacks an option like this?
-
Have had to re-install Reader as a result of harware failure. How do we activate the PDFMaker add-on which is still current on the new installation?
-
Alright, I've found a couple things here about this, but its not solving my problem as mine is a little different. I have. Tiger, DVDSP 4.2.1 Designing a dvd with motion menus, etc. Now. I have three files Transition movie into first menu first menu
-
How to use two libraries on two different pc
I have a MAcBook Pro and a Windows XP Pro with both itunes 7 installed on each. How can I share my songs with both libraries without resetting the ipod. We hav three ipod (2-nano (2 Gigs) and one video 60 gigs.) In my family we are three who sharing
-
hi, how do i search BADI's for T.code QM01. Thanks N Regards Priya.