Calling Procedure/Package in shell script
how to call a package / procedure in a unix shell scripts. also how to schedule jobs in shell scripts.
That's usually accomplished by run sqlplus from shell script.
http://www.oracle-base.com/articles/misc/OracleShellScripting.php
Crontab can be used to schedule jobs in unix.
http://www.adminschoice.com/docs/crontab.htm
Similar Messages
-
How can i call a Stored Procedure procedure from Unix shell script
Hi All,
I want to call a Strored PL-SQL Procedure through Unix shell script.
Can any body help me with this.
Regards,
SaurabhI prefer a seperate script like the other poster mentioned. However, most shells can use a 'here' document as well ...
sqlplus uid/pwd <<END
exec myproc
exit
ENDRichard -
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 -
How to Call Multiple Sessions through Shell scripting
Dear Members,
I have a scenario where I load data into target table from 20 different source tables.
For this I have written three procedures where there exists an bulk insert executed on a same table in every procedure. Now I have to call these procedures simultaneously so that
all three bulk loads are executed at once in different sessions.
For this I have to write a shell script which opens 3 different sessions and execute all these packages at once.
Can you guide me through.When you call sqlplus in your shell script, put a & at the end so that it runs the SQL scripts in the background. For instance:
#!/bin/bash
...oracle home stuff
$ORACLE_HOME/bin/sqlplus user/pass @script.sql &
$ORACLE_HOME/bin/sqlplus user/pass @script2.sql &
$ORACLE_HOME/bin/sqlplus user/pass @script3.sql & -
Calling HTML File in Shell Script.
Hi
I have a shell script and a HTML file.
HTML file is to create a Table.
the HTML Script is as follows
<html>
<body>
<table border="1">
<tr>
<td>Requisition Number</td><td>$PARAM0</td>
</tr>
<tr>
<td>Purcahse Order Number</td><td>$PARAM4</td>
</tr>
<tr>
<td>Purchase Line Number</td><td>$PARAM5</td>
</tr>
<tr>
<td>Hold Reason</td><td>$PARAM3</td>
</tr>
<tr>
<td>Hold Date</td><td>$PARAM2</td>
</tr>
</table>
</body>
</html>
The output of this HTML file is a table with 5 rows and 2 columns.
I saved this file as mail.html and placed it in the server where i have placed the Shell Script.
When i call this HTML in Shell Script ... as follow
cat /FND_TOP/bin/mail.html
the output is not the table but infact the html tags are displayed.
I need the table when i run this shell script.
It would be of great help if anyone has a good solution for this.
Thanks in AdvanceFirst, you need to put the file where your httpd server (you will need apache running) can find it. This is usually some place like:
/var/www/html/table.htmlThen use a text-mode browser as Frits suggested to render it so your script can read it:
#!/bin/sh
lynx -dump http://localhost/table.html | while read row; do
echo "${row}"
doneor how ever you want to process the data.
Another approach is to use XML transformations. First write an XML stylesheet:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" version="1.0">
<xsl:output indent="no" method="text" standalone="yes" version="1.0"/>
<xsl:template match="*">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="td">
<xsl:text> </xsl:text>
<xsl:value-of select="normalize-space()"/>
</xsl:template>
</xsl:stylesheet>and then run your HTML through the {font:Courier}xsltproc{font} processor:
$ xsltproc table.xsl table.html
Requisition Number $PARAM0
Purcahse Order Number $PARAM4
Purchase Line Number $PARAM5
Hold Reason $PARAM3
Hold Date $PARAM2To be neat, I have omitted the many blank lines that were also output.
HTH -
How we can call or execute a SHELL script through Oracle forms or Reports
How we can call or execute a SHELL script through Oracle forms or Reports.Its urgent.......
Use HOST command.
-
Can I call host file ( Unix Shell script ) from Oracle 10g trigger
Hi,
I am new to Oracle 10g. Can I call host file ( unix shell script ) from Oracle 10g trigger ?. I know it is possible. Pl explain me with small example
thanks & regards
paraguser12009546 wrote:
Hi,
I am new to Oracle 10g. Can I call host file ( unix shell script ) from Oracle 10g trigger ?. I know it is possible. Pl explain me with small example
thanks & regards
paragIf you are in 10g, you can simple call shell script from DBMS_SCHEDULER:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'TEST_SCRIPT',
job_type => 'EXECUTABLE',
job_action => 'PATH_OF_YOUR_SCRIPT',
start_date => SYSDATE,
repeat_interval => 'FREQ=MINUTELY; INTERVAL=1',
enabled => TRUE,
comments => 'Shell script from Oracle'
END;
/ -
Invoking a Package.Procedure via bash shell script
Hello All,
I am using the below syntax to call package in a unix shell script, is this right way of calling and checking for errors or is there any other better approach?? kindly suggest.
I am using Oracle 11g & Linux OS, SQL*Plus: Release 11.2.0.3.0 Production
RETVAL=`sqlplus -s FCSDWH_STG/${DBSTG}@${DBSRC} <<EOF
EXEC FCSDWH_STG.FCA_HASH_TOTALS_PKG.HASH_TOTALS_COMPUTE(${PROVIDER},${UNINUM},${EXTRACT_DT},${VER_NUM});
EOF`
if [ `echo ${RETVAL} | egrep "ERROR"` ]
then
logit "Error While Generating The SQLPLUS Output File, Please Check"
exit 1
else
logit "SQLPLUS Output File Has Been Generated Successfully"
fiThanks much.Ariean wrote:
I am testing the same above functionality with the below sample procedure, and I am purposefully making it compile erroneous with "dbms_output.put_lin" just for sake of testing.
create or replace
procedure today_is as
begin
dbms_output.put_lin('Today is : ' || to_char(sysdate,'DL'));
end today_is;This is sample shell script "test.sh" I am using
#!/bin/bash
RETVAL=`sqlplus -s FCSDWH_STG/FCSDWH_STG@dwdev <<EOF
set termout off
exec today_is;
EOF`
echo "start here"
echo ${RETVAL}
echo "end here"
if [ `echo "$RETVAL" | grep "ERROR"` ]
then
echo "Error While Generating The SQLPLUS Output File, Please Check"
exit 1
else
echo "SQLPLUS Output File Has Been Generated Successfully"
fiBelow is my output
start here
BEGIN today_is; END;
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00905: object FCSDWH_STG.TODAY_IS is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
end here
/home/infrmtca/bin/test.sh: line 8: [: too many arguments
SQLPLUS Output File Has Been Generated SuccessfullyI don't understand why it is printing "SQLPLUS Output File Has Been Generated Successfully" though it errored out.Because statements within backquotes are executed before the statement calling the backquote. The [ command has too many arguments coming from the echo and grep. You might put just that test part of the script in it's own little script and test it, it seems to say that whether there is an ERROR in $RETVAL or not. You might need to man test and see if you need a -z argument or something.
>
Edited by: Ariean on May 15, 2013 10:08 AM
Edited by: Ariean on May 15, 2013 10:16 AM -
Calling SQL statements from Shell scripts
Hi,
I want to call external package procedures, declare some variables & do some oracle validations in the shell script.
How SQL environment is set in shell script & is this one time process or I have to write few statements before every SQL statement.
Please explain with an example.
Thanks..is this one time process Yes. Example :
$ cat script.sh
export ORACLE_HOME=/home/oracle/base/OraHome10
export ORACLE_SID=db102
export PATH=$ORACLE_HOME/bin:$PATH
sqlplus -s / as sysdba << EOF
select to_char(sysdate,'dd/mm/yyyy hh24:mi:ss') date_time
from dual;
exit
EOF
sqlplus -s / as sysdba << EOF
col global_name for a60
select * from global_name;
exit
EOF
$ ./script.sh
DATE_TIME
27/02/2008 11:11:27
GLOBAL_NAME
DB102
$ -
Advice executing oracle package using shell script.
Hi,
I am writing one shell script that accepts several parameters as an input. These parameters are then passed while executing Oracle package procedure. However this procedure has an OUT parameter and I am not aware of how to receive that parameter in shell script.
Any advice /suggestion is really appreciated.
Below is the part of code I am using ... (P_OUT is suppose to be an out parameter for package)
sqlplus -s apps/apps <<endsql
whenever sqlerror exit failure
set serveroutput on size 10000
execute TEST_PKG.GET_COC_REQ ('$P_FROM_DATE','$P_TO_DATE','$P_MONTH_YY', '$P_OUT');
endsqlThere is more than one way. Here an example :
SQL> select ename,sal from emp where empno=7902;
ENAME SAL
FORD 3000
SQL> create or replace procedure extsal (
2 empnum in number,
3 salout out number)
4 is
5 begin
6 select sal into salout
7 from emp
8 where empno = empnum;
9* end;
SQL> /
Procedure created.
SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
$ EMP=7902
$ SAL=`sqlplus -s scott/tiger << EOF
set head off
var salout number;
exec extsal ($EMP, :salout);
print salout
exit
EOF
`$ echo $SAL | awk -F. '{print $2}'
3000
$ -
Unable to pass parameter in oracle procedure through unix shell script
Hi Experts,
I have oracle procedure where in I have to pass the value of procedure parameter through unix script.
Follwoing is the sample procedure which i tried to exceute from the unix.
Procedure:
create or replace procedure OWNER.PRC_TESTING_OWNER(OWNER IN VARCHAR2) AS
sql_stmt varchar2(1000) := NULL;
v_count number := 0;
v_owner varchar2(100) := owner;
begin
sql_stmt:='select count(1) from '||v_owner||'.EMP@infodb where rownum<=10';
execute immediate sql_stmt into v_count;
DBMS_OUTPUT.PUT_LINE(sql_stmt);
DBMS_OUTPUT.PUT_LINE(v_count);
END;The script which I used is:
Unix
#!/bin/ksh
parm=$1
echo start
sqlplus -s scott@DEV/tiger <<EOF >>result_1.txt
set serveroutput on;
select '$parm' from dual;
exec owner.PRC_TESTING_OWNER('$parm');
EOFThe script is working fine that is i am able to pass to parameter value through unix shell script. :)
But if I want to pass the value of the owner in cursor , I am unable to pass this value through unix.
Following the procedure which i am trying to implement.
create or replace procedure OWNER.PRC_TESTING_OWNER(OWNER IN VARCHAR2) IS
v_owner varchar2(100) := owner;
CURSOR main_cur IS
select
i.ROWID rid ,
emp_name,
deptid
from v_owner.employee;
CURSOR subset_cur(c_deptid NUMBER ) IS
SELECT *
FROM v_owner.DEPT d
where d.dept_id=c_deptid;
--##main loop
FOR i IN main_cur LOOP
FOR j IN subset_cur(i.deptid) LOOP
BEGIN
insert into v_owner.RESULT_TABLE
END;
END LOOP;
END LOOP;How can i pass parameter value of the stored procedure through unix script(that is "owner" in this case), when these parameter value is
used in cursor? :(
Can anybody help me regarding the same?
Thanks in Advance !! :DIt's not the parameter in the cursor that is the problem, it's that you are trying to use static SQL for something that won't be known until run time (the owner of the table).
You would need to use something like ...
declare
l_owner varchar2(30) := 'SCOTT';
l_ref_cursor sys_refcursor;
type l_ename_tab is table of scott.emp.ename%type;
l_ename_array l_ename_tab;
begin
open l_ref_cursor for
'select ename
from ' || l_owner || '.emp';
loop
fetch l_ref_cursor bulk collect into l_ename_array limit 10;
exit when l_ename_array.COUNT = 0;
for x in 1 .. l_ename_array.count
loop
dbms_output.put_line(l_ename_array(x));
end loop;
end loop;
close l_ref_cursor;
end;
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01 -
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? -
Dear All,
I want to call an sql script within a unix shell script. I want to pass a parameter into the shell script which should be used as a parameter in teh sql script.
e.g
$ ./shell1.sh 5000129
here 5000129 is a prameter
inside shell script i am calling one sql script
e.g.
@script1.sql;
inside the sql script I have an update statement
UPDATE abc set xx = 22 where id = 500129;
as you can see the 5000129 passed as shell script parameter, is being passed as parameter in the sql script.
Please can you advise how can I achieve this?
Many Thanks,Hi
You could try something like this.
tmpSQLFile=$EXTLOG_DIR/tmpSQLFile_$$.sql
tmpSpoolFile=$EXTLOG_DIR/tmpSpoolFile_$$.sql
export ORACLE_PWD=`cat /home/oracle/secure/runtime_user.dat`
echo "spool $_tmpSpoolFile" > $_tmpSQLFile
echo "SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON LINESIZE 10000 TIMING OFF" >> $_tmpSQLFile
echo "begin" >> $_tmpSQLFile
echo "DW_MGT_SCHEMA.PKG_RUNTIME_HANDLER.SP_UPD_RUNTIME_EXT_CTL_LOG_TDT(p_transfer_date => '$today', p_schedule_id => $schedule_id);" >> $_tmpSQLFile
echo "end;" >> $_tmpSQLFile
echo "/" >> $_tmpSQLFile
echo "exit" >> $_tmpSQLFile
sqlplus ${ORACLE_USER}@${ORACLE_SID} @$_tmpSQLFile << EOT
`echo $ORACLE_PWD`
EOTCheers
Gary -
Calling sql from a shell script
I have code like the following
sqlplus -s /nolog >> EOF
select 1 from dual;
EOF
Is it possible for me to pass result set to a shell variable or do I have to spool it to a file and then read the file?what is the best way to parse a multi-column, multi-row result set. lets say i have a query that has 9 rows and 2 columns.
this query was
select sysdate, 1
from user_objects
where rownum < 10
07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 -
Calling sqlplus from unix shell script
Hi All,
I am executing the following code :-
sqlplus -s ${DATABASE_USER} |&
print -p -- 'set feed off pause off pages 0 head off veri off line 500'
print -p -- 'set term off time off serveroutput on size 1000000'
print -p -- "set sqlprompt ''"
print -p -- "SELECT run_command from tmp_run_batch where upper(batch_name) = upper('${PAR_PROGRAM_NAME}');"
read -p RUN_COMMAND
eval print -p -- \""execute dbms_output.put_line(${RUN_COMMAND});"\"
read -p RET_VAL
print -p -- "exit;"
The select stmt given above gives sample output as :-
pack_claims_clas_utils.func_main('$PAR_RUN_DATE','$PAR_RUN_LEVEL','$PAR_EXCLUSIVE_RUN_YN')
And then this package is executed.
The problem that I am facing is how to handle the no_data_found case of the select stmt. . When this case arises then the stmt. "read -p RUN_COMMAND" hangs.
Could you please provide any solution ?
Thanks
SudsHi,
Have you tried this:
# if [ -n means String has non-zero length
if [ -n $RUN_COMMAND ]
read -p RUN_COMMAND
fi
Hi All,
I am executing the following code :-
sqlplus -s ${DATABASE_USER} |&
print -p -- 'set feed off pause off pages 0 head off veri off line 500'
print -p -- 'set term off time off serveroutput on size 1000000'
print -p -- "set sqlprompt ''"
print -p -- "SELECT run_command from tmp_run_batch where upper(batch_name) = upper('${PAR_PROGRAM_NAME}');"
read -p RUN_COMMAND
eval print -p -- \""execute dbms_output.put_line(${RUN_COMMAND});"\"
read -p RET_VAL
print -p -- "exit;"
The select stmt given above gives sample output as :-
pack_claims_clas_utils.func_main('$PAR_RUN_DATE','$PAR_RUN_LEVEL','$PAR_EXCLUSIVE_RUN_YN')
And then this package is executed.
The problem that I am facing is how to handle the no_data_found case of the select stmt. . When this case arises then the stmt. "read -p RUN_COMMAND" hangs.
Could you please provide any solution ?
Thanks
Suds
Maybe you are looking for
-
Registration page not working in modal window
Hi could use some wisdom here, The page is setup to appear in a modal window. However, when you click on "Register Now" button the page appears, then disappears very quickly. This of course does not permit customer interaction, and I can't tell what
-
How to import jpegs at 100 dpi?
The main layer of my movie is a jpeg at 100 dpi. When I import it to the stage, Flash converts it to 72 dpi, which makes everything too small. I'm using Flash MX. Do later versions of Flash support 100 dpi, and if yes, which ones? If no, what can I d
-
I'm loving the CSS features proposed by this project and demo'd with the MiniBrowser. I'd really like to be able to print examples to share with colleagues who don't have access to this browser yet. But the print option in MiniBrowser seems broken -
-
Everyone, Can somebody explain me how to change JVM paramters in Configtool step by step. I opened configtool and Instance_IDXXXXX,Right side i see Servers General and Java Parameters. I changed the parameters,saved and restarted the cluster. But,the
-
Hello, I am trying to download Oracle Help for the Web (OHW). From this page: http://www.oracle.com/technology/tech/java/help/index.html if I click on "Oracle Help for the Web", I get this page: http://www.oracle.com/technology/software/tech/java/hel