Running Stored Pocedures from UNIX
Hi,
Does anybody have an example of a Unix script that kicks off a series of stored procedures (after checking the status of the previous one) within a package?
Thanks
Raj
hi
use like this
sqlplus -s bo/bopassword@wsstest @t.sql
PL/SQL procedure successfully completed.
contents of t.sql are like this
exec some_proc
exit
once you execute the above command sqlplus -s ....
it connects in silent mode with the specified username,password and connect string and it executes the specified script
and the output of the commands in the script t.sql will be returned. capture the output/redirect the output of the command
and check for the string PL/SQL procedure succesfully completed.
then you can think that the procedure is executed succesfully if not you can take necessary action
hope this helps
all the best
prakash
[email protected]
Similar Messages
-
Running stored procedure from unix shell
Hi
I have a stored procedure proc1 stored in a file, code1.txt in my home directory /home/user. How do i execute this file which contains the stored procedure from unix shell? I would really appreciate it if somebody gives me the complete shell script to accomplish the above task.
Thanks.To put everything together into a single posting:
The EXEC command is a SQL*Plus macro command. It is not a SQL or PL/SQL command.
The only way to execute a stored proc from a client, is to wrap the call in an anonymous PL/SQL block. I.e you need a BEGIN and END PL/SQL wrapper around the call.
E.g.BEGIN
-- calling a stored proc to start leave processing
scott.StartLeaveProcessing;
END;The EXEC macro in SQL*Plus does this automatically for you. Thus less typing. But do not confuse this command with the PL/SQL language.
Second issue. Use bind variables when making calls from clients. And not just for SQL statements, but also for PL/SQL. Unfortuantely this tends to be a hack in SQL*Plus due to the way SQL*Plus itself treats its bind variable assignments. But in principle, this is what you should do when calling an Oracle stored proc from a client:
SQL> -- define a host variable
SQL> var EMPID varchar2(100)
SQL> var FROM_DEPT number
SQL> var TO_DEDPT number;
SQL>
SQL> -- assign values to these (this is where SQL*Plus hacks it)
SQL> exec :EMPID := 100;
SQL> exec :FROM_DEPT := 1;
SQL> exec :TO_DEPT := 2;
SQL>
SQL> -- now make the stored proc call for moving employee 100 from
SQL> -- department 1 to department 2
SQL> EXEC scott.EmployeeTransfer( :EMPID, :FROM_DEPT, :TO_DEPT );
SQL>To do this from a Unix shell script:
#!/bin/bash
# environment variables
# --> put environment such as ORACLE_HOME, ORACLE_SID, TWO_TASK
# etc. here <--
# redirect STDIN from TTY (keyboard typewriter device) to the input from
# this file - which means SQL*Plus will not read from the keyboard but read
# from this file its input until the EOF marker/text is encountered
sqlplus -s /nolog << EOF
connect scott/tiger
var EMPID varchar2(100)
var FROM_DEPT number
var TO_DEDPT number;
exec :EMPID := 100;
exec :FROM_DEPT := 1;
exec :TO_DEPT := 2;
exec scott.EmployeeTransfer( :EMPID, :FROM_DEPT, :TO_DEPT );
exit;
EOF
#eof -
Calling stored procedure from unix shell script
Hello,
I am facing a problem while calling a stored procedure from UNIX shell script. I want to return a output variable from the stored procedure to the UNIX environment.
Here is the code-
#!/bin/sh
OUTPUT=`sqlplus cmag/magnum@dw <<ENDOFSQL
set serveroutput on;
var prd_out varchar2(100);
exec create_pm_window(:prd_out);
exit;
ENDOFSQL`
echo " output is - $OUTPUT"
The problem is :prd_out is not getting copied to shell variable OUTPUT.
I have a dbms_output.put_line in the stored proc create_pm_window and I can see that prd_out is getting populated.
Any help is really appreciated.
Thanks'
RakheeFirst step :
make sure the PL/SQL works as expected.
Does the following display the expected output executed from SQL*Plus ?
set serverout on
declare
prd_out varchar2(100);
begin
create_pm_window(prd_out);
dbms_output.put_line('output is '||prd_out);
end;
I don't have your procedure, but using a dummy procedure like :
Scott@my10g SQL>create procedure foo(p_out in out varchar2)
2 is
3 begin
4 select 'Hello '||instance_name into p_out from v$instance;
5 end;
6 /
Procedure created. and a toto.sh script as :OUTPUT=`sqlplus -s scott/tiger <<EOF
set pages 0 lines 120 trimout on trimspool on tab off echo off verify off feed off serverout on
var mavar varchar2(100);
exec foo(:mavar);
print mavar;
exit;
EOF`
echo "OUT = ${OUTPUT}"
exitIt works fine :[oracle@Nicosa-oel ~]$ ./toto.sh
OUT = Hello my10g -
When running a scenario from Unix ( $ prompt)it cant found the DTD for xml
Dear All,
I have created an interface that extracts xml messages from JMS queue ( OC4J) successfully. After extracting the message from JMS queue, the interface parse the message and put into an oracle database.
After when I have created a scenario from the above Interface and tried to run the scenario from $ promt in unix using startscen.sh, it is giving following error message.
# call the configuration setup file--- Mandatory for running ODI scenario
. $ODI_HOME/bin/odiparams.sh;
# Call the scenario for getting Message from JMS queue
. $ODI_HOME/bin/startscen.sh PKG_JMS_XML 001 GLOBAL "-v=5" | tee out_$$.txt;
The error I am getting as below
03/09/2009 05:09:40 PM(main): SnpExpTxt.getObjectLst : :
[FirstDate:2009-03-09 17:09:40.0
FirstUser:SUNOPSIS AGENT
IndChange:null
IntVersion:null
ITxt:5194100
LastDate:2009-03-09 17:09:40.0
LastUser:SUNOPSIS AGENT
Txt:0 : 08001 : java.sql.SQLException: Cannot load connection class because of underlying exception: 'java.sql.SQLException: No DTD found and no XML file provided: the XML schema cannot be created'.
java.sql.SQLException: Cannot load connection class bec
TxtOrd:0, FirstDate:2009-03-09 17:09:40.0
FirstUser:SUNOPSIS AGENT
IndChange:null
IntVersion:null
ITxt:5194100
LastDate:2009-03-09 17:09:40.0
LastUser:SUNOPSIS AGENT
Txt:ause of underlying exception: 'java.sql.SQLException: No DTD found and no XML file provided: the XML schema cannot be created'.
at com.sunopsis.jdbc.driver.JMSXMLDriver.connect(JMSXMLDriver.java)
at com.sunopsis.sql.SnpsConnection.u(SnpsConnection.
TxtOrd:1, FirstDate:2009-03-09 17:09:40.0
FirstUser:SUNOPSIS AGENT
IndChange:null
IntVersion:null
ITxt:5194100
LastDate:2009-03-09 17:09:40.0
LastUser:SUNOPSIS AGENT
Txt:java)
at com.sunopsis.sql.SnpsConnection.c(SnpsConnection.java)
at com.sunopsis.sql.i.run(i.java)
TxtOrd:2]
Anybody please help ?
regards
UmapadaHello,
Try to remove and recreate your package and scenario, I had the same issue and solved doing it.
It seems for me that the package cannot update its contents, for example, if you change something in your interface, you must recreate your package and scenario to update the changes.
What ODI version do you use? If you use an old version, try to update to ODI 10.1.3.5
Regards,
Wallace Galvão
São Paulo - Brazil -
Hi
I am trying to remember how to run OWB client (10gr1) from a unix command. Can anyone please help with what command you run from unix?
Thanks
GBHi,
To start Warehouse Builder using UNIX:
1.Start a shell.
2.Navigate (cd) to <OWB ORACLE HOME>/owb/bin/unix
3. Invoke owbclient.sh
Thanks,
Sutirtha -
Can anybody tell me how to run PL/SQL Procedure from unix prompt.
You can start a sqlplus script from unix prompt, e.g.
sqlplus <youruser>/<yourpassword>@<yourdb> @yourscript.sqlEdited by: hm on 01.01.2011 02:33 -
Running stored procedures from HTML DB
Hello.
Is it possible to run stored procedures/functions from HTML DB? If yes, how to do it?
DavideIf the variable v_return_amount is a number, how can you assign a boolean to it? Are you sure your function is valid? I would write it slightly different:
CREATE OR REPLACE FUNCTION verify_amount (
v_invoices_pk IN NUMBER,
v_new_amount IN NUMBER
RETURN BOOLEAN
IS
CURSOR c_amount
IS
SELECT amount
FROM invoices
WHERE invoices.invoices_pk = v_invoices_pk;
CURSOR c_dist_amount
IS
SELECT SUM (cost_distribution.amount)
FROM cost_distribution
WHERE cost_distribution.invoices_pk = v_invoices_pk;
v_sum_amount NUMBER;
v_invoices_amount NUMBER;
BEGIN
OPEN c_dist_amount;
FETCH c_dist_amount
INTO v_sum_amount;
CLOSE c_dist_amount;
OPEN c_amount;
FETCH c_amount
INTO v_invoices_amount;
CLOSE c_amount;
IF (v_invoices_amount <= v_sum_amount + v_new_amount)
THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
RETURN v_return_amount;
EXCEPTION
WHEN OTHERS
THEN
RETURN FALSE;
END;
Other than that, I am not sure about your cursors but I can't judge from here. The other thing is how you use the function in the validation process. Can you try to correct and tell if it worked out?
Denes Kubicek -
Running Stored functions from PHP
Hi all,
I cannot find any proper example in which it is detailed how to run an oracle stored function (or function within a package) from php.
i.e. this is my function
create or replace function myfunction return date is
begin
return sysdate;
end myfunction;
this is my php (but doesn't work)
function OracleExecutefunction($pconnection){
$sql = "declare v_date date; begin v_date:=myfunction; end;";
$result = OCIParse($pconnection,$sql) or OracleProblem();
OCIExecute($result, OCI_DEFAULT) or OracleProblem();
return $result;
This is what I get: Resource id #4
I would appreciate any help or much better a working example.
CheersOK, i have it working now by doing the following:
function OracleExecutefunction($pconnection){
$sql = 'select myfunction mdate from dual';
$result = OCIParse($pconnection,$sql) or OracleProblem();
OCIExecute($result, OCI_DEFAULT) or OracleProblem();
OCIFetch($result);
#echo "My function=" . ociresult($result, "MDATE");
return ociresult($result, "MDATE");
Is there any other better way of doing it?
Thanks -
Execute stored procedure from Unix shell script
My current method of executing stored procedures (wpl_1 and wpl_2) from a unix shell script is as follows:
<<wpl.sh>>
sqlplus user/password @/home/oracle/scripts/wpl.sql
<<wpl.sql>>
set serveroutput on size 1000000
set timing on
execute wpl_1('0000010676','~')
execute wpl_2('0000010676','~')
execute wpl_1('0000010236','FIX')
execute wpl_2('0000010236','FIX')
exit
Question: Is it possible to combine the two scripts (unix and oracle) together?A little rusty on this, but this may work:
My current method of executing stored procedures
(wpl_1 and wpl_2) from a unix shell script is as
follows:
<<wpl.sh>>sqlplus user/password @/home/oracle/scripts/wpl.sql << EOF
set serveroutput on size 1000000
set timing on
execute wpl_1('0000010676','~')
execute wpl_2('0000010676','~')
execute wpl_1('0000010236','FIX')
execute wpl_2('0000010236','FIX')
exit
EOF
>
Question: Is it possible to combine the two scripts
(unix and oracle) together? -
Running Stored procedures from Forms
I have several stored procedures (stored in the database) that I
want to run from Forms (client), but when they're running my
application (in Forms) is frozen until the procedure end.
I don't know how to run that stored without lock the application,
somebody Can Help me???
THANKS
nullThe second parameter of the DBMS_JOB.SUBMIT procedure needs to be
a valid PL/SQL call, i.e. it must at least be terminated by a
semicolon. You could also wrap it into an anonymous PL/SQL block,
like: 'BEGIN SP_CREA_FACTURAS_PADRE; END;'
Marisol (guest) wrote:
: Dietmar:
: I put this code in my application and I didn't get any response
: DBMS_JOB.SUBMIT( iJobNumber,
: 'SP_CREA_FACTURAS_PADRE',
: SYSDATE,
: 'null',
: FALSE);
: COMMIT;
: When I select the option that executes this code my application
: ends without any message...
: You know why is this happen?
: How can I resolve??
: Thanks :)
null -
Running sql script from unix using
Hello!
When i run the following sql, it doesn't executes any statement after the 1st SQL.
anyone know the reason?
#!/bin/bash
set -x
echo test
sqlplus /nolog << EOF
set serveroutput on size 1000000
conn userid/pwd@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=10.92.xxx.xxx)(Port=1521))(CONNECT_DATA=(SID=oradbid)))
select '1st sql output' from dual;
exit
EOF.
sqlplus /nolog << EOF
set serveroutput on size 1000000
conn userid/pwd@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=10.92.xxx.xxx)(Port=1521))(CONNECT_DATA=(SID=oradbid)))
select '2nd sqloutput' from dual;
exit
EOF
--------------------------------You have to remove . (dot) after first EOF.
Best regards
Maxim -
How to Run Stored Procedures from Teststand
I am trying to get teststand to run an SQL stored procedure but I always get the following error
Error executing substep 'Post'.
The following SQL command failed: 'EXECUTE cdt_st_test...'
Native error code -2147217900 0x80040e14
Microsoft OLE DB Provider for SQL Server:
Syntax error or access violation
It is a test stored procedure that doesn't pass any parameters.
Which steps must I use and how do I pass parameters.I have sussed it now. I was setting the "Command Type" to stored procedure instead of default. I changed it back and did "EXECUTE cdt_st_test" and it works. I have also added the parameters there as well.
-
Pro Oracle App Express issue : Running stored proc from link in e-mail..
Just ran into an issue and need some help with it. A person I work with was using code from John Scott's book (Great Book for APEX!!) and was using the verification e-mail link code, when it started acting up.
The e-mail that is sent is to call a procedure in a database package (pkg_auth) procedure is called send_verification_email. We moved his code up to my hosted area on Oracle's site so I could help further.
The e-mail is sent properly, but when the link is clicked through, the following error is returned from the server:
Bad Request
Your browser sent a request that this server could not understand.
mod_plsql: /pls/otn/f HTTP-400 Missing '=' in query string or post form
The link that is being clicked is:
[http://apex.oracle.com/pls/otn/ACT_SOFTWARE.pkg_auth.verify_user?p_user=becky&p_code=D62B94845A5E8A5149CCB391CE53D31B]
Two parameters being passed are user name and a verification key.
I am stumped since we compared his code to what John has in his book and except for changes in e-mail addresses and server information (don't visit apexdemo.com, its a company in Washington state..)
Thank you,
Tony Miller
Webster, TXOnly tested on Oracle's site right now. He was working on local machine with code, thus we moved to hosted site so we could work together..
Execute rights granted to PUBLIC for named package.
WWV_FLOW_EPG_INCLUDE_MOD_LOCAL: Since this is on Oracle's hosted site, can't really change this setting..
Funny thing is, I believe before the 3.2.1 update, I had a version of this working in a demo for someone (deleted it since then...) now it seems to be having issues..
Strange, the url is being re-written as : [http://apex.oracle.com/pls/otn/f?p=&APP_ID.:101:&APP_SESSION.] after the error is displayed. Also that the url seems to long for the address bar and I need to scroll right..
Thank you,
Tony Miller
Webster, TX
Edited by: Tony Miller on Oct 14, 2009 1:51 PM -
Scripting pl/sql from unix
I am wondering if there is a way to do this with certain restrictions. If not, I can do it another way.
1. I have a list of values in a unix .txt file of the form
VALUEA
VALUEB
VALUEC
I know how to read a list in unix using a loop.
2. I want to call a pl/sql anonymous block that I have in a .sql file 1 time for every value in this script and pass the value.
I do know how to read a value and then pass it to a pl/sql parameter and then call the pl/sql parameter.
What I don't know how to do is
Do this with only logging into sqlplus one time. I dont want to do the following
unix runs in a loop
reads 1 record from file
logs into sqlplus
runs the procedure and passes the value
log out of sqlplus
end loop
I want to
1. read all the values from the file
2. store it somehow in memory (variable of some sort)
3. pass this value to the pl/sql procedure
I do not want to make any objects in the database such as a global temporary table.
Yes I can actually do this, but wondering if it is possible to avoid. Makes it easier to deploy to alot of different databases. If I have to make a database object, then i have to make an object in alot of databases. If I can run it all from unix, all I have to do is change the target and the password. So it is easier to deploy.I don't need to put this in an Oracle Directory. I am not calling anything from pl/sql stored in the database. It is going to all be done with unix scripts and anonymous block sql in .sql statements in the OS. This allows me to take advantage of clustered storage (I can have alot of databases servers mounted on 1 directory). So the unix script will log into oracle and call the .sql script.
I can build the pl/sql dynamically. I'd rather not do that. The thing is I have alot of databases I want to deploy code to. So I am trying to come up with a pattern I can follow. So if I add a new database or what to deploy somewhere else, I can just use add a line to a file.
Adding database objects every time I need to deploy to a new database is a pain. It is far more scaleable to handle all of this in unix.
Edited by: Guess2 on Jan 12, 2010 7:43 AM -
Running ssh command from java and then answering password prompt
Hi,
I have a situation that has not solved yet. I am running ssh command from unix terminal without any problem, and then i enter password.
For example :
[oracle@fuata]:/export/home/oracle> ssh -N [email protected] -L 9901:127.0.0.1:9999
Password:
It is working. I have question that how can i perform this in java? I am thinking that i can run ssh command by using Runtime Class, it is ok. But how can i answer the password? I am a bit confused. Is there any example looks like this?
Thanks for responses.futi wrote:
Thanx. Firstly i insisted to do this without jsch but actually this is harder than jsch. I edit some of code pieces PortForwardingL.java and could run it. It works problem-free. Could you say why you "insisted" on this approach. It can't be for speed+ since jsch is very fast. It can't be for portability+ since jsch is portable but the use of Runtime.exec() requires the installation of ssh software. It can't be because of limitations+ since jsch is a fully featured library. It can't be for security+ since jsch is secure. It can't be for ease of use+ since jsch is much easier to use than ssh with Runtime.exec(). Unless it's a licensing issue, it can't be for commercial+ reasons since jsch is free. The only reason I can think of why one would "insisted" on this approach is if it is for some college project.
Maybe you are looking for
-
How to parse a raw string that returns an XML file?
Guys, Good day! I was assign to work on this but I did'nt know what to start. Please help me. The Problem is something like this: xml-file = pword(raw data string, token interpretation string) returns an XML file of: token type, token (value), positi
-
How to make pictures appear in different project/albums ?
Hi, I face an organisational problem using Aperture. I created a "Portraits" Folder where I created several projects for each character I use to shoot. I also have a "Events" folder where I store Projects containing all the pictures related to a part
-
Hi, I'm having issues generating a BCP XML format file using a fairly unusual column terminator, a double dagger symbol ‡ (alt + 0135) which I need to support. I'm experiencing this problem with bcp.exe for SQL2008 R2 and SQL2012. If I run the follow
-
Location case for laptops in Digital Photography
Hello everyone I am a professional photographer often using a laptop on location to store and process my images. I've been looking for and not finding a case I can have the laptop in as well as have it open with a dark viewing cover. And ofcorse I wo
-
Why do I have to double touch my apps to work?
Why is my touch now speaking instructions to me? I touch the photo app once and it says" photos, double tap to open". Please help me stop this. Thanks