Call unix script within plsql block
Hi all,
can i call a unix script within a plsql block for example
my unix script name is - Diff_dataload_process.sh
declare
begin
select * from ......;
Diff_dataload_process.sh
exception
end;
please help me.
Thanks,
Krupa
Hi, I think you need something like this:
DBMS_SCHEDULER.create_program
(program_name => 'sch_program',
program_type => 'EXECUTABLE',
program_action => '/home/nobody/input/test_job.sh',
number_of_arguments => 0,
enabled => TRUE,
comments => 'Test Program'
end;
and there's another ways to do it:
[calling shell|http://www.dba-oracle.com/t_execute_shell_script_plsql_procedure.htm]
Similar Messages
-
Call unix script within Servlet - need to wait for completetion
Hi,
I have a servlet which grabs some information from my web form and then calls a unix script.
This already works fine and does what i need it to do. I now need to add some functionality where i can get the servlet to wait for the unix script to complete before carrying on and then redirecting back to the user.
the code i have for the current servlet is:
* EXECUTE THE UNIX COMMAND.
Runtime oRuntime = Runtime.getRuntime();
Process oProcess = null;
String[] cmd = {"/bin/sh", "-c", sPath}; // UNIX
* ERROR CODES 3 = File not found
try
oProcess = oRuntime.exec(cmd);
catch(Throwable t)
t.printStackTrace();
}I am assuming i need some sort of wait method to handle this. Any help would be greatly appreciated.
Thanks
Grahamok.. you code is fine.. you can run any shell script or program using the exec() method. if you need to wait till the process finishes then you need to call the method waitFor() in class Process.. the method blocks the parent thread (servlet) till the sub process (your exec'd script or program) terminates.
hope that solves your problem.. :-)
Pls tell me one more thing.. are you using netBeans or Eclipse for executing the programs or you use standalone tomcat to deploy the application. I have problem in execing programs when i deploy in tomcat 5.5 and the same application works fine in netBeans 5.0. if you know pls help me too..
Thanks,
-- abdel Olakara. -
How to call unix script/command in ODI
Hello Gurus,
Please let me know how to call unix script/command in ODI?
Thanks
Shridharyou can call shell script using the OS command found in Package.
Step 1. Drag the OS Command in the Packgae
Step 2. In the Text mentiond call the script say for ex sh /opt/path/script.sh
Step 3. Execute.
Note : Make sure the User through which ODI is triggering does have the required permission to execute shellscript , also always provide the full path , since scripts are execute from the oracldi/bin folder so its necessary to provide the complete path of the script location.
Hope this helps. -
Hi all ,
I have tried unix command from PLSQL Block,
Please see the code.
DECLARE
stat INTEGER;
host_command varchar2(100);
errormsg VARCHAR2(80);
command varchar2(2000);
BEGIN
command:='touch /home/oracle/testting.txt';
dbms_pipe.reset_buffer;
host_command:= dbms_pipe.unique_session_name;
dbms_output.put_line('host_command:'||host_command);
dbms_pipe.pack_message(command);
dbms_output.put_line('pack message:'||command);
stat := dbms_pipe.send_message(host_command);
dbms_output.put_line('stat:'||stat);
IF stat <> 0 THEN
raise_application_error(-20000, 'Error:'||TO_CHAR(stat)||' sending on pipe');
END IF;
stat := dbms_pipe.receive_message(host_command);
dbms_output.put_line('stat2:'||stat);
IF stat <> 0 THEN
raise_application_error(-20000, 'Error:'||TO_CHAR(stat)||' receiving on pipe');
END IF;
dbms_pipe.unpack_message(errormsg);
dbms_output.put_line('errormsg:'||errormsg);
IF errormsg <> 'SUCCESS' THEN
raise_application_error(-20000, 'Execution error: '||errormsg);
END IF;
END;
Nothing happend from this code just getting only following result with error.
-----------------result-----------------------------
host_command:ORA$PIPE$002D19820001
pack message:touch /home/oracle/testting.txt
stat:0
stat2:0
errormsg:touch /home/oracle/testting.txt
DECLARE
ERROR at line 1:
ORA-20000: Execution error: touch /home/oracle/testting.txt
ORA-06512: at line 33
Can any one tell me what i doing wrong in this code.
I m working on Oracle 11g and AIX unix server.This is the forum for the SQL Developer product, not for general PL/SQL questions. There is a link to the SQL and PL/SQL forum in the announcement at the top of this forum.
-
Calling unix script using oracle forms
we have to call unix script using oracle forms , a trigger in form calls stored procedure on database
that stored procedure on database calls a oracle shared library
but since the only listener account for oracle on our unix server is oralist , whenever a call is made to the unix script from the oracle form , the unix script is executed by oralist user
but issue that we are having now is since oralist is specific for listening connections from orale we dont want to use this user to establish SFTP on it to avoid any issues with oralist
we want the sftp to be established on soem other useraccount , so is it possible to do something so that the script is executed by an account other that oralist.I'm not a Linux/Unix specialist, but I think this may work: let your database call a shell script that does a su command before running the actual script:
su - other_account
your_script.sh -
Calling Unix-Script from within Oracle and store stdout/stderr in table
Hi,
What I want to do is:
1. Calling a UNIX script (e.g. hello.sh) (from inside the Database)
hello.sh
echo Hello World!
2. and get the stdout/stderr output back in my Database in a table (e.g. temp_back)
table temp_back
ID stdout stderr
1 Hello World!
I think Number 1 isnt a big problem, but how to get stdout back in DB?
Any solution?
I searched a bit in this Forum and found this Post.
re:Calling Host Command Through Database Procedures or Triggers
This may be what I am searching for, but cant access the Link
Since I am not really fit with UNIX and packages/procedures in Oracle it would be nice if you could post a very detailed answer.
(Please no java)
-What packages do I need? (heard DBMS_OUTPUT would be useful)
-example PL/SQL script
Thanks a lot!
Marcus
Environment:
Oracle 9.2.0 DBMarcus, if you opened the Java sandbox to access any o/s file, you can call any Unix command, shell script, or program, that the Oracle o/s user has exec privs on.
Just remember that there's a very basic Unix environment when you make the call - the settings in the .profile does not apply. Thus PATH for example is not set. When making the call make sure that the complete path is given. As for the environment, that is a problem as you cannot set that and make the call at the same time.
In that case it is much simpler to rather write a Unix shell script that does all for you. Set the environment. Run the command(s). Format output. Etc.
Then you call that Unix script, via Java, from SQL or PL/SQL. Treat the Unix scripts like the Unix-version of stored procedures for your Oracle application.
Some technical details. When you connect to Oracle, a Unix process services you. This can be either a dedicated server process (servicing only your Oracle session) or a shared server process (from the shared service pool of processes).
In either case, it is a Unix process running as a background process (thus detached from any tty device). PL/SQL and SQL are executed by this process. The Oracle JVM created by your session also lives in this process. When you therefore make o/s calls, these calls are made by this process.
Therefore you are limited to what this process can and can't do. E.g. it runs as the oracle o/s user and will fail on accessing paths and commands does the oracle user does not have privs on. Etc. -
Calling UNix Script from portal Form
Has anyone conquered this issue through jav or plsql. I need to call a unix script from the portal form when I select the insert button.
I have several very convoluted ways which all work, but I have always thought there should be more straightfwd ways. Fundamentally the easiest way to call something from the Insert button is to add some PL/SQL code before (or after) the "doInsert();" call in the Insert Button event handler.
What seems to be lacking is the ability to get from pl/sql to the o/s. So until we know how to do that you have to call a method in Java to execute o/s commands - specifically you can use Runtime.getRuntime().exec(cmd); where Runtime is a class in java.lang, and cmd is the actual o/s command (script or whatever).
How to call this Java is then where you have several options:
1. Compile this piece of Java into the Oracle DB as a SP.
2. Deploy this piece of Java within a Java servlet on a 9iAS instance. Then have another SP call this servlet using the utl_http package (begin_request and other sp's within package).
Which options would depend on several factors including your preference but most importantly whether you have a DB or a 9iAS instance on the machine where you want to execute the script. If you have neither you have a problem. In such cases I have used a standalone OC4J container which has a very small footprint.
As I said these methods are all quite convoluted and if anyone else has anything better I would like to know (but they work quite reliably).
Cheers.
Anton. -
Calling perl script from PLSQL
Hi All,
I have created Java stored procedure and oracle function to execute the os commnad, this works fine for calling batch scripts but when i used same function to call perl script,
like how we call in batch script
perl <script name> the sql gets hanged.
Is it possible to call perl like this?
or is their any other way to call from plsql
Thanks ChandraAre you able to run that perl script at DOS command line?
Did you call the perl script directly from the java proc or you put the perl command line in a DOS .BAT scirpt and called that from the java proc? -
Hi all,
I'm having unix scripts for file validation.How and where to call this Unix scripts in ODI?Please be in steps.
Advance thanks
SureshHi Suresh,
Its very straight forward in ODI.
For your package, click Tools, under Utilities you will find, OSCommand, type the exact path of your script file and make sure your agent should have all access rights to invoke the script.
http://img19.imageshack.us/img19/5584/screenshot030z.jpg
Thanks,
G -
Call Unix Script from JSP.
Hi,
I need to run a unix script from a JSP page.
JSP pages reside on a different machine.
How can i call the unix script resides on different machine from JSP.
Thanks,
Narendrayah. I can access that machine telnet and having all credentials of that system.
Can you please share the code needed for this.
Thanks,
Narendra -
Calling sql script from anonymous block
Hi
how to call an script from an anonymous block, like
declare
v_reccord_account number :=0;
begin
SELECT xx.cc INTO v_reccord_account FROM
(select count(1) cc
from accounts
group by account_id
having count(account_id) > 1
)xx
where ROWNUM=1;
if v_reccord_account <1
then
dbms_output.put_line('no duplicates');
ELSE
< here i have to call this script -- @e:/test44.SQL >
end if;
end;Hi
thanks for replying, i'm having some sql statements, i have to spool the results of those statements .. below is the content of the file i'm calling.
=================================================
whenever sqlerror exit sql.sqlcode
set serveroutput on
column fn new_value filename
select 'remove_duplicates_'||to_char(sysdate, 'yyyymmddhh24miss')||'.log' as fn from dual;
spool E:/&filename
prompt 'Checking for duplicates'
--select account_id, count(1)
--from accounts
--group by account_id
--having count(1) > 1;
prompt 'Records to be deleted'
select *
from accounts
where decode ( substr(account_id,1,3),'COG',1,0)=1
group by account_id
having count(1) > 1;
prompt ' Deleting duplicates'
delete
from accounts
where account_id in (
select account_id
from accounts
where decode ( substr(account_id,1,3),'COG',1,0)=1
group by account_id
having count(1) > 1
commit;
========================================== -
Executing unix script within java and getting the return value
Hi
I am executing a unix script from within java which will return me a value. Is there a way I get this value and use it inside my java code without doing this:
BufferedReader in = new BufferedReader( new InputStreamReader( ls_proc.getInputStream() ));
//readLine reads in one line of text
int k = 1, i = 0;
while (( ls_str = in.readLine()) != null)
--kirk123I was hoping to get what I want in one or two line codes.
--kirk123 -
Calling sql script in plsql procedure
Hello,
I have a sql script named mytest.sql and i want to execute this from a stored procedure.
following is the contents of this script
spool d:\mytestsql.txt
select * from tab;
spool off
Actually i want my sql script to run daily to export some tables data.
I can execute this script from a sql prompt but i want to run it from enterprise manager.
I am using oracle 10gR2 on windows2000 system.
Any idea about scheduling the sql script to run automatically??
How to execute this sql script from a plsql procedure??
ThanksHi all,
Thanks for all the replies. I have found the solution with external procedures.
Following is the complete step by step guide.
1. Create the OSCommand Java Class using the following statement:
connect as any user:
create or replace and compile java source named oscommand as
import java.io.*;
public class OSCommand{
public static String Run(String Command){
try{
Runtime.getRuntime().exec(Command);
return("0");
catch (Exception e){
System.out.println("Error running command: " + Command +
"\n" + e.getMessage());
return(e.getMessage());
2. Create the following Wrapper Function using the following statement:
CREATE or REPLACE FUNCTION OSCommand_Run(Command IN STRING)
RETURN VARCHAR2 IS
LANGUAGE JAVA
NAME 'OSCommand.Run(java.lang.String) return int';
3. connect as sys
Execute dbms_java.grant_permission( 'FKHALID','SYS:java.io.FilePermission', '<<ALL FILES>>','execute');
execute dbms_java.grant_permission( 'FKHALID','SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '*' );
execute dbms_java.grant_permission( 'FKHALID','SYS:java.lang.RuntimePermission', 'readFileDescriptor', '*' );
commit;
note: here fkhalid is the oracle user.
connect as fkhalid user:
Declare
expdp_cmd Varchar2(2000);
Begin
expdp_cmd := OSCommand_Run('cmd /c sqlplus fkhalid@mtcedwt/pwd @d:\ORA_DUMPS\mydbexp.sql');
DBMS_OUTPUT.Put_Line(expdp_cmd);
End;
In Unix
Set Serverout On
Declare
x Varchar2(2000);
Begin
x := OSCommand_Run('/home/test/myoscommand.sh')
DBMS_OUTPUT.Put_Line(x);
End;
I will check the dbms_scheduler also and will let you know the results.
Thanks -
Accepting UNIX variable in PLSQL block
Hi,
I wanted to send shell variable to a PL/SQL block in a SHELL script. ?How to achieve this?
I am using Korn Shell.
Thanks & Regards
LAKSHMISend the parameters to sqlplus and access them
================================
This call
================================
C:\Temp>sqlplus issues/issues@air @t.sql Parameter1
================================
Makes this
================================
SQL*Plus: Release 8.0.6.0.0 - Production on Mon May 6 12:48:54 2002
(c) Copyright 1999 Oracle Corporation. All rights reserved.
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production
With the Partitioning option
JServer Release 8.1.7.0.0 - Production
SQL> BEGIN
2 DBMS_OUTPUT.Put_Line ('HI &1');
3 END;
4 /
old 2: DBMS_OUTPUT.Put_Line ('HI &1');
new 2: DBMS_OUTPUT.Put_Line ('HI Parameter1');
PL/SQL procedure successfully completed.
SQL>
SQL>
SQL>
SQL> /*
DOC>
DOC>set serveroutput on size 1000000
DOC>clear screen
DOC>@c:\temp\t.sql
DOC>
DOC>*/
SQL> -
Execute immediate issue while calling a procedure from plsql block
Hi all,
I have the following simple code ,my execute immediate is not working(I am pasting the error below as well)
CREATE OR REPLACE PROCEDURE CALL_RAHUL_PROCEDURES
AS
strng varchar2(1000);
BEGIN
for i in (select proc_name,flag,id from rahul_procedures order by id)
loop
if (i.flag = 'Y')
then
strng := 'exec '||i.proc_name||'(''rahul'')';
dbms_output.put_line(strng);
execute immediate strng;
end if;
end loop;
END CALL_RAHUL_PROCEDURES;
Error:
Connecting to the database INQDWD.
ORA-00900: invalid SQL statement
ORA-06512: at "ETLADMIN.CALL_RAHUL_PROCEDURES", line 17
ORA-06512: at line 2
exec RAHUL_HELLO_WORLD2('rahul');
Process exited.
Disconnecting from the database INQDWD.
data in rahul_procedures table :
Proc_name flag Id
RAHUL_HELLO_WORLD N 1
RAHUL_HELLO_WORLD2 Y 2
RAHUL_HELLO_WORLD N 3
RAHUL_HELLO_WORLD3 N 4
please help.
Regards
RahulMac_Freak_Rahul wrote:
Well I have to call 26 procedures one by one and the names of the procedures would be in a table'rahul_procedures' Which is 100% wrong.
Data is stored in tables, program code is stored in procedures or view defintions.
http://en.wikipedia.org/wiki/Data_%28computing%29
>
Data vs programs
Typically, different files are used to store programs vs data. Executable files contain programs; all other files are data files.
>
So you have just violated the primary distinction between data and program code.
I dont find anything strange in my question,Only because you do not appear to know what you are doing or the difference between data and program code.
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1943344500346351703
>
ugh, what an ugly "design". I can see your life will be full of performance issues, strange 'bugs', and other unpleasant side effects. I mean, it all looks "so cool", but it'll be a nightmare to maintain and enhance.
but then you have the issue of binds, which will be intractable. You'd have to know the binds at compile time, but you have hidden all of your sql in a magic generic table - so you cannot possibly know your binds at compile time.
I would suggest you discard all of this code (I am DEAD SERIOUS) and start over. This is a bad idea from the get go. Or at least do me a favor and do not use plsql (you make it look like a good database implementation, but it isn't)
The objective here is to store SQL Statements in a Table(a sql repository) and just call the required SQL from the application using the sqlid using the sql_execute procedure. ...
CHANGE YOUR OBJECTIVE.
How about this for a good objective:
the objective here is to store sql statement in a plsql routine (a sql repository, you call a procedure and we run sql) and just call the required sql form the applicatoin using the STORED PROCEDURE
sorry, can I think of hacks to get you going? yes, application contexts come to mind - a fixed number of binds comes to mind. Am I going to work them out? No - it is the wrong way to approach a database application.
Maybe you are looking for
-
Manually uninstall acrobat 9.5.2
My computer keeps crashing everytime I use acrobat 9.5.2. A blue screen comes up and states "PAGE_FAULT_IN_NONPAGED_AREA." I tried uninstalling through control panel / uninstall and this crashes the computer. I downloaded the Adobe Acrobat Cleaner To
-
Create a Distribution Certificate as a p.12 file in Keychain Access not working?
I need to create a Distribution Certificate as a p.12 file. I downloaded my ios_distribution.cer file from iOS Provisioning Portal/Certificates/Distribution/Download but this file will not install on my Keychain Access Certificates. Once installed I
-
How to watch tv with FX 5600 XT vtdr 128
How to watch tv with FX 5600 XT vtdr 128?
-
CMS Transport Load Software Component Configuration
Hi All, We have done the Development SOAP to RFC scenario. We are trying to move the chages to QA system through CMS transport, we did't find the SC in Add SC, for that we have updated the CMS and tried to load SC configuration while doing this we ar
-
Max resolution of HDMI on Retina Macbook Pro
I'm in the process of trying to eliminate my older tower from my life and just use my Macbook Pro Retina as my sole machine and am having trouble with the displays. My goal is to run at least one of my NEC PA271W monitors if not both. The trouble is