Oracle declare function in shell script
Please tell me oracle declare function now able to run in shell script?
I am calling in shell script like @/myscript.sql it is not working properly, reset update and other oracle command is working fine in shell script.
I am running below code.
#!/bin/sh
sqlplus system/manager@prod_db <<ENDOFSQL
update apps.fnd_concurrent_queues set node_name = 'host1', target_node ='host1' where node_name='host3';
update apps.fnd_concurrent_queues set node_name = 'host2', target_node ='host2' where node_name='host4';
commit;
DECLARE
VALUE BOOLEAN;
l_node_id number;
BEGIN
select node_id into l_node_id from fnd_nodes where NODE_NAME = 'host5';
VALUE := fnd_profile.save ('NODE_TRUST_LEVEL', 3, 'SERVER',l_node_id,null,null);
END;
ENDOFSQL
Below ERROR i am getting after running above code via shell script with oracle user
SQL>
0 rows updated.
SQL>
0 rows updated.
SQL>
Commit complete.
SQL> SQL> DECLARE
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 5
Similar Messages
-
Hello,
I have the following function in PL/SQL:
Create or replace function fqman."test" (name in varchar2, url in varchar 2, page in varchar2, uname in varchar2, password
in varchar 2, key_ in varchar2, pass in varchar2, file1 in varchar2, file2 in varchar2) return number
as language java
name 'Data.file(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,
java.lang.String,java.lang.String,java.lang.String) return int;Data is a java class I have in my /home directory (AIX machine). I would like to run this function NOT through Oracle, but through a shell script. So, I have to write the test function in a .sh file.
I started doing that. I did the following:
fntest()
name =$1
url=$2
page=$3
uname=$4
password=$5
key_=$6
pass=$7
file1=$8
file2=$9
}I do not know how to finish the function. Any help will be appreciatedPerhaps the following will do:
#!/bin/bash
fntest() {
name="'$1'"
url="'$2'"
page="'$3'"
uname="'$4'"
password="'$5'"
key="'$6'"
pass="'$7'"
file1="'$8'"
file2="'$9'"
ORACLE_SID="ORCL"
export ORAENV_ASK=NO
. oraenv -s
sqlplus -s / nolog <<EOF
set pages 0 feed off
connect username/password
BEGIN DBMS_OUTPUT.PUT_LINE(fqman.test($name,$url,$page,$uname, etc..)); END; /
exit;
EOF -
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 -
PL/SQL function - unix shell script
Hello,
I have an application that calls a unix shell script This unix shell script calls a oracle function in the PL/SQL package. For example,
In package pkg_test, there is function f_test. This function returns pls_interger.
How can I write a unix shell script to return the value from the oracle function, so that the application can get the value from the unix shell script?
Many thanks.Thank you for your response.
The Oracle functuion pkg_name.proc_name will return different values, 0, 1, 2, 3 in diffefrent conditions.
The unix script, myscript.ksh calls pkg_name.proc_name.
The other application will call myscript.ksh and this application will need to get the values 0, 1, 2, 3 from myscript.ksh.
Can we make it without using the unix shelll function?
Thanks.
Edited by: slsam01 on Jun 2, 2009 9:21 PM -
Executin oracle stored procedure from shell script
Hi everyone,
I want to know how to execute a orace stored procedure from a shell script not a sql file.
Its a oracle stored procedure with in parameters.
Can anyone send immediate reply its very urgent.
Thanks in Advance
with regards
ThazulHello everyone,
Whenever i am using the previous script
because of <<! and !>> in the beginging and the end of oracle scrip. Shell is displaying the error 'newline or ;' unxexpeted and the error no is 48.
After that i used a different script like
DIRRUNNER=/oracle/tvg
count=0
while [ 1 -eq 1 ]
do
for x in `ls $DIRRUNNER/RUNNER_*.TXT`
do
count=`grep -c $x $DIRRUNNER/runner.log`
if [ $count -lt 1 ]
then
chstr=`echo $x|awk -F/ '{printf $NF }'`
dir=$DIRRUNNER
file=$chstr
PATH=$PATH:/usr/local/bin:.
export PATH
ORACLE_SID=BBPROD
ORAENV_ASK=NO
. oraenv
ORAENV_ASK=YES
echo "exec runrace('$dir', '$file')" > runner.sql
sqlplus -s tvgus/tvgus@bbprod @runner.sql
echo $x >>$DIRRUNNER/runner.log
fi
done
count=0
sleep 2
done
The above one is working fine but after executing the procedure control is still remaing in the sqlplus environment, but i want the control back to my shell
Can anyone help to resolve this, its pretty urgent.
Thanks in Advance
Thazul.
null -
Oracle 10g and Korn Shell Scripting
I have a table,SALES_STAGING, with 3 main columns.
Sales_Date, Sales_type,Sales_Code.
A sale is added to the table then waits until approved to be processed. The Sales_Code is 1(waiting approval). Then manually changed to 2 every 30 minutes by sales staff except on weekends. By Monday,a large queue develops. This must be changed because the queue is slowing the system. Can someone help create a Unix Korn shell script to
1) Run every 30 minutes via Crontab
2)login to the Oracle DB.
3)Count the number of records to be processed, if any.
4)Update another 'log' table with the time it ran and the records to be processed
5)if there are less than 20 add another 50 to be processed by changing the Sales_Code from 1 to 2.
This would really help out tremendously! Thank you.Wait... Isn't this forum designed for the sharing of information? The experts here shouldn't be concerned whether the request is from a Student, Oracle newbie or Developer and should focus on the request. If you are capable of assisting then I am hoping you will out of the core respect for professionalism and the motivation to provide something of value to others. If not, don't waste my time or any one else by responding with preconceived judgments and insulting remarks as these will be reported.
Sales transactions can peak at 20,000 per hour with an average of several million thru the week. Those sales by VIP customers are immediately identified and have a priority for approvals because their balances can easily exceed $1,000,000.00. There is a pre-approval process to be introduced but until programs can be modified/tested and deployed we need a quick fix. The programming system isn't slow, it's the limited human resources approving VIP customers. My request was to keep it simple and expand on it myself to include the entire scope of our project. dbms_scheduler, although a good idea will require DBA assistance and there is no resource available. I need a simple working model to give me some direction/ideas... -
Oracle Error Handling in Shell Scripts
I need to manage 2 diferente class of errors :
Oracle Errors(produced in compilation time) and
Operating Syste Error(e.g. No Datbase conection ORA-1017,etc) my shell its KSH.
Please can you help me how can I manage then?
this my alternative but is not correct ;
#creating conexion with sql
exit | sqlplus -s $USERPV_DB/$PWDPV_DB @$VORDSQLPATH/ord.extractor_porven.sql $VFDESDE $VFHASTA > $VORDDATOS_PATH/ord.extractor_porven$VDATE.dat 2>> $VLOG
#Evaluating last sentence (sqlplus . . . . )
VERROR=$?
#Si VERROR=0 should stop process execution and alert with echo ".."Oracle error handling before compilation time
if [ $VERROR != 0 ]
then
echo "value of VERROR are:$VERROR"
echo "`date +"$V_FORMATDATE"` DATA EXTRACTION WAS NOT SUCESSFUL ERROR BEFORE COMPILATION TIME" >> $VLOG 2> /dev/null
" Here show VERROR
else #Oracle error handling in compilation time
echo "`date +"$V_FORMATDATE"` DATA EXTRACTION WAS NOT SUCESSFUL ERROR BEFORE COMPILATION TIME " >> $VLOG
" Here show VERROR
else if [ $VERROR = 0 ]
" DATA EXTRACTION WAS SUCESSFUL"
fi
Would apreciate your help its very urgent.
Best Regards
Antoniouser5647282 wrote:
I need to manage 2 diferente class of errors :
Oracle Errors(produced in compilation time) and
Operating Syste Error(e.g. No Datbase conection ORA-1017,etc) my shell its KSH.
Please can you help me how can I manage then?
this my alternative but is not correct ;
#creating conexion with sql
exit | sqlplus -s $USERPV_DB/$PWDPV_DB @$VORDSQLPATH/ord.extractor_porven.sql $VFDESDE $VFHASTA > $VORDDATOS_PATH/ord.extractor_porven$VDATE.dat 2>> $VLOG
Piping the output of 'exit' to sqlplus????????? what do you expect from this?
#Evaluating last sentence (sqlplus . . . . )
VERROR=$?any error returned by sqlplus as $? would be a fatal error of sqlplus itself, not any error returned by processing a sql statement. If your script ord.extractor_porven.sql were to generate, say, an ORA-00001, that is NOT an error in sqlplus and so does not return to the OS as an error of sqlplus.
#Si VERROR=0 should stop process execution and alert with echo ".."Oracle error handling before compilation time
if [ $VERROR != 0 ]
then
echo "value of VERROR are:$VERROR"
echo "`date +"$V_FORMATDATE"` DATA EXTRACTION WAS NOT SUCESSFUL ERROR BEFORE COMPILATION TIME" >> $VLOG 2> /dev/null
" Here show VERROR
else #Oracle error handling in compilation time
echo "`date +"$V_FORMATDATE"` DATA EXTRACTION WAS NOT SUCESSFUL ERROR BEFORE COMPILATION TIME " >> $VLOG
" Here show VERROR
else if [ $VERROR = 0 ]
" DATA EXTRACTION WAS SUCESSFUL"
fi
Would apreciate your help its very urgent.
there is no "urgent" here.
"Urgent" means one of two things -
1) people are dying, or
2) you have a customer-facing, revenue-producing production system that is down.
(And to get some perspective on the second case, keep the first in mind.)
For the first, you call whatever civil emergency service seems appropriate.
For the second, you open an SR with Oracle - which requires a paid-up support contract. For them to consider your problem "urgent", you will need to demonstrate that your problem falls under item #2. I seriously doubt your problem fits that criteria.
Best Regards
Antonio -
Insert file to oracle db by C shell script
Hi,
Could you pls help me how I can write script on C shell of Sun solaris to load data to Oracle database from text file with "," fields separator. Send me the samples script if can. Thanks you very much.
Vu Tuan - Vietnam Mobile Telecom services co.Thanks Yoann very much, I tested sqlldr already as your help, But problem with me is how to set ulcase2.dat is variable in ulcase2.ctl file?, following is script in SunSolaris, how I can use SQLDLR command in this scrip? :
find $LOADER_DIR -type f ! -size 0 -print | egrep 'RLOS.txt' | \
while read file
'How to input $file to RLOS tables exist in ortacle database by sqlldr format as following "
(sqlldr USERID=scott/tiger CONTROL=ulcase2.ctl LOG=ulcase2.log)
esac
done
could you pls see an help me.
thankis in advands -
Catching oracle exception in shell script
Hi,
I'm trying to catch an oracle exception in a shell script. Below is my shell script -
#!/bin/sh
var=115326311
logfile=shell_log.txt
sqlplus -s mbl/sop01 <<EOF
WHENEVER SQLERROR EXIT SQL.SQLCODE;
@plsql.sql $var;
EOF
return_type=$?
if [ $return_type != 0 ]
then
echo 'Error with code';
echo "$return_type";
exit 0;
fi
and this is the sql script -
set serveroutput on;
DECLARE
--set serveroutput on;
--v_company_id NUMBER := 'company_id';
v_name VARCHAR2(100);
BEGIN
--set serveroutput on;
dbms_output.ENABLE();
SELECT ename INTO v_name FROM emp WHERE emp_ID = &1;
DBMS_OUTPUT.PUT_LINE('Inside SQL File'||' || '|| v_name);
END;
exit
I'm basically passing an employee number that does not exist and hence the sql file would throw and no_data_found exception, which i'm trying to catch in the shell script. When I try to execute the shell script I get the below error --
DECLARE
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 8
Error with code
123
he sql file is aborting and the error there is just thrown to the command line, which I don't want. I want it to be captured in the shell script and perform my own logic. Also, it says the error code is 123 - I'm not sure from where this is being picked up, shouldn't it actually be the ORA-1403 code ?Hello,
1403 is out of range for the return value, see https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1342602684748
We can raise errors in a given range but the shell will only keep an
unsigned byte in the status return value (values 0..255). It takes our exit file and
just looks at that last byte.
It also shows how to get around this limitation.
Regards
Marcus -
Shell scripting for oracle DBs
looking for good source for shell scripting for oracle DBs
Just buy 'Classic Shell Scripting' and 'the Unix Desktop Reference' both published by O'Reilly and you have it all.
But if you want a platform agnostic scripting language use Perl. Comes with Oracle.
However both bash and kornshell are a lot easier compared to Perl.
Sybrand Bakker
Senior Oracle DBA -
DBMS_SCHEDULER and Shell Script on 10.2.0.1
Hi All
My env, Oracle 10.2.0.1 and OS is Solaris.
My script can run on OS that is work without error that contain create file, delete file, call sqlplus, function to get value from database and return to OS variables.
In shell script some code as below
get_val () {
sqlplus -s /nolog <<EOF
conn test/test
set heading off
set feedback off
set pages 0
SELECT SUBSTR (SYS_CONNECT_BY_PATH (Z, ' '), 2) z
FROM (SELECT NAMEDQUERY , ROW_NUMBER () OVER (ORDER BY Z) rn,
COUNT (*) OVER () cnt
FROM X
WHERE Z LIKE '%FULL')
WHERE rn = cnt
START WITH rn = 1
CONNECT BY rn = PRIOR rn + 1;
EOF
vx=$(get_val)
if [ ${#vx} -gt 0 ]; then
for xfile in $vx
do
rm -f $CURRDIR/$xfile.txt 2> /dev/null
done
fi
When run by dbms_scheduler that show below error
ORA-27369: job of type EXECUTABLE failed with exit code: No such file or directory
STANDARD_ERROR="/home/oracle/script/test.sh: syntax error at line 26: `vx=$' unexpected
How to resolve above error? (owner of $CURRDIR/$xfile.txt is oracle user)
One more question, How to force dbms_scheduler that using user oracle (OS) to run shell script?, as I know, default user is nobody and Oracle version 10.2.0.2 later that have external.job.ora to set it but 10.2.0.1 doesn't have it.
Thank you in advance,
HikoI changed scheduler by set argument as below
dbms_scheduler.create_job (job_name=>'TEST',job_type=>'EXECUTABLE',job_action=>'/usr/bin/bash',number_of_arguments=>1);
dbms_scheduler.set_job_argument_value('TEST',1,argument_value,'/home/oracle/test.sh');
That is work. below is conclusion to did
1. Change permission of $ORACLE_HOME/bin/extjob to 4750 (-rwsr-x---)
2. Change owner of $ORACLE_HOME/bin/extjob to oracle:dba
3. Use '/usr/bin/bash' instead of '/usr/bin/sh'
But I found error about download file process that I'm using wget to download source file in shell script and run by dbms_scheduler as above.
My problem, first file can download normally and process until finish but second file was hang.
Do you have any idea or solution to prove and resolve it?
Thank you,
Hiko -
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
$ -
How to write CLOB parameter in a file or XML using shell script?
I executed a oracle stored procedure using shell script. How can i get the OUT parameter of the procedure(CLOB) and write it in a file or XML in UNIX environment using shell script?
Edit/Delete MessageSQL> var c clob
SQL>
SQL> begin
2 select
3 DBMS_XMLGEN.getXML(
4 'select rownum, object_type, object_name from user_objects where rownum <= 5'
5 ) into :c
6 from dual;
7 end;
8 /
PL/SQL procedure successfully completed.
SQL>
SQL> set long 999999
SQL> set heading off
SQL> set pages 0
SQL> set feedback off
SQL> set termout off
SQL> set trimspool on
// following in the script is not echo'ed to screen
set echo off
spool /tmp/x.xml
select :c from dual;
spool off
SQL>
SQL> --// file size
SQL> !ls -l /tmp/x.xml
-rw-rw-r-- 1 billy billy 583 2011-12-22 13:35 /tmp/x.xml
SQL> --// file content
SQL> !cat /tmp/x.xml
<?xml version="1.0"?>
<ROWSET>
<ROW>
<ROWNUM>1</ROWNUM>
<OBJECT_TYPE>TABLE</OBJECT_TYPE>
<OBJECT_NAME>BONUS</OBJECT_NAME>
</ROW>
<ROW>
<ROWNUM>2</ROWNUM>
<OBJECT_TYPE>PROCEDURE</OBJECT_TYPE>
<OBJECT_NAME>CLOSEREFCURSOR</OBJECT_NAME>
</ROW>
<ROW>
<ROWNUM>3</ROWNUM>
<OBJECT_TYPE>TABLE</OBJECT_TYPE>
<OBJECT_NAME>DEPT</OBJECT_NAME>
</ROW>
<ROW>
<ROWNUM>4</ROWNUM>
<OBJECT_TYPE>TABLE</OBJECT_TYPE>
<OBJECT_NAME>EMP</OBJECT_NAME>
</ROW>
<ROW>
<ROWNUM>5</ROWNUM>
<OBJECT_TYPE>TABLE</OBJECT_TYPE>
<OBJECT_NAME>EMPTAB</OBJECT_NAME>
</ROW>
</ROWSET>
SQL> -
Need to call Shell script that uses SQL loader in APex4.1/11g
Hi there!
I have a requirement, wherein I have to call a shell script that connects to an external server, ftp's a file in and then uses sqlloader to load data into our table. Now we have the ftp script that does this for another program, but is a scheduled job. I wanted to call the ftp shell script from within APEX. Any suggestions on how this can be done, what PL/SQL logic can we use? I see online some people using dbms scheduler for this?
Thank you
SunHi,
Create some sh script on your oracle host machine where you can join into external server and run the process.
something like:
run_external_sh.sh
#!/bin/sh
ssh ext_user@ext_host ./sqlloader/import/import.shThen create a external JOB to call it via ORACLE(PL/SQL)
-- Call Shell Script.
BEGIN
DBMS_SCHEDULER.create_program (
program_name => 'external_call_sh',
program_type => 'EXECUTABLE',
program_action => '/local_host/call_external/sh/run_external_sh.sh',
number_of_arguments => 0,
enabled => TRUE,
comments => 'Call external SH script');
END;
/Now you can create a scheduled/or not scheduled JOB
-- Job defined by an existing program and schedule.
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'jb_external_call_sh',
program_name => 'external_call_sh',
schedule_name => 'external_call_scheduler', -- created scheduler
enabled => TRUE,
comments => 'Job defined by an existing external_call_sh program and schedule.');
END;
/Now you can call the JOB in APEX in PL/SQL process.
BEGIN
-- Run job synchronously.
DBMS_SCHEDULER.run_job (job_name => 'jb_external_call_sh');
END;Regards
J :D -
Call Unix Shell Script From OBIEE
Hi All,
Is it possible to do a call to a Unix Shell Script with the Action Framework from OBIEE.
Thanks in AdvanceI dont think so but we can go for it instead of BI side. Try to port the same functionality on shell script side, so that the script can identify your report using tail of nqquery log and execute the rest of your lines in shell script.
This can doable and works as expected. If at all you are going with my suggestion you can go for a small key word to identify your report instead of that lengthy logical query.
Pls mark if helps
Maybe you are looking for
-
What is the best way to declare field length 500 in internal table?
Hi all, what is the best way to declare field length 500(constant value allways) in internal table? I am trying to send data from internal table to file format, and I have a field in internal table with 500 length (constant value always). So how do I
-
Webmail Vacation Rule - Mass spam
We have seen this issue several times now if one of our users enables an existing vacation rule (created in the client) in webmail it will go through and send an email to several (if not hundreds/thousands) of people they have corresponded with withi
-
Oracle to MS SQL porting - dynamic sql - cursors
I have a stored procedure written for oracle which needs to be ported to MS SQL. Used SSMA to do that but the dynamic sql statements are not getting ported and are the same. Below is a dynamic sql from the SP after making changes with SSMA. SET @dsql
-
Improve the performance of the data activation on DSO.
Hi, I would like to improve the performance of the data activation on DSO. 1000 records should be uploaded by 10 minutes. Now it takes 10 minutes to activate data in DSO. And it is strange that it takes long time ( about 9 minutes) before starting ac
-
Associated Dimension in Detail Variable Disappears
Hi there, Verion: BOBJ 4.1 SPS2. When creating a DETAIL VARIABLE on a report with MULTIPLE QUERIES which has MERGED OBJECTS the associated dimension is accepted but then is missing when you reopen the variable. Also, when I use the variable it work