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 !! :D
It'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
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 read specific line in a file through UNIX shell script..
Dear Friends,
I have generated .ldt file under admin/import/US folder through FND_LOAD script for Download the responsibility.
I registred Shell script (Host concurrent program) in Oracle apps. Now i want to read the file in speciific line which i was generated in admin/import/US folder through unix shell script. Please help me how to read specific line and the i want to replace that which i am going to read the specific line.
Thanks in advance..
Regards,
Velu.Hi,
Thanks for reply,
My requirement i have to find the specific line in a file and find and replace needed word over there it's should happen programatically. i want to read specific line in a file Once complete find and replace the condition should exists. The loop will go to next file and read the same line in next file also do the same process upto how many files over there.i am doing through UNIX shell script. Please help me out to find the
Your suggestion is highly appriciated.
Thanks,
Velu. -
How can i pass parameter values from html to a shell script
Hi Guys...
I had a requirement where i need to execute a sql statement and print the output in HTML page. This report has parameters to enter. So i created a HTML form which accepts parameters. When the submit button is pressed, the action tag in the form invokes unix shell script file. It will open sqlplus and run the sql script file .sql and print the output in the HTML page.
sql script contains the query and some set options which prints the output in HTML page. Like "SET MARKUP HTML ON"... The query has some parameters like "select * from emp where empno = &&empnumber. I will use the same name "empnumber" while created the HTML parameter form like " <input type = "text" name="empnumber" size="10" align="left">.
user sees this parameter form and enters some value in to that empno text box.
My question is how can i catch these parameter values in a shell script and pass it to the sql script to execute it.
Help Appreciated
ThanxThis is a A Bad Idea (tm). This type of CGI processing is old and were (and still is) full of security holes. Very easy to inject stuff (Unix commands and SQL) into it.. To get those parameters into SQL*Plus requires using Unix shell commands to process it - and something like a backquote allows all kinds of nasty stuff to be injected. The Unix shell was never designed to be used as a secure CGI environment.
There are far better and far superior alternatives. Perl (with Perl_DBI) and PHP (using Zend Core for Oracle) come to mind as web scripting languages.
Even easier is using HTMLDB. Very few moving parts. Is free. Supports Oracle 9.2 and 10G. -
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? -
Passing parameters to query called through a shell script
I have a file called getInfo.sql that contains a query like:
spool ./myInfo.txt
select *
from myTable
where col1 = '&val1'
and col2 = '&val2';
spool off
I would like to call SQLPLUS from a shell script and pass this file in as a parameter. How would I pass in the values for
&val1 and &val2 ?
Any help would be appreciated.
Thanks
RajanYes, you put a line in the script that looks like this:java classname parameter1 parameter2 parameter3 ...Then the JVM will call the static main(String[] args) method of "classname" and put those parameters into the "args" array.
If you are asking how to generate such a script, or how to call it from your COBOL program, sorry, I don't know how to do that. -
Parameter transfer to tmloadcf from Unix shell script.
Hi.
I am using Tuxedo global transaction with database password encryption, so I replaced by ***** the database password in OPENINFO string of the TMS in the UBBCONFIG GROUP section.
As a result the password should be inserted manually when running tmloadcf.
Do you know how this password can be inserted from a Unix shell scripts?
I tried to use << or named pipe (mkfifo) but in both cases the tmloadcf remained stuck.
Thanks in advance for your help.
Amnon Katz.Amnon,
The C library function isatty() is used to determine if tmloadcf is
associated with a terminal. If isatty(0) returns 0, then the tmloadcf code
to prompt for a password will fail.
In some places in Tuxedo, there is functionality to allow reading a password
from an environment variable if the process requiring the password is not
associated with a terminal. However, this functionality is not available
for tmloadcf. If you have an active Tuxedo maintenance contract and the
functionalty of reading a database password from an environment variable
when tmloadcf is not run from a terminal is important to you, you may want
to file a support case and request that this functionality be added to
tmloadcf. Otherwise, you will have to run tmloadcf from a terminal.
Regards,
Ed
<Amnon Katz> wrote in message news:[email protected]..
Thanks Ed for your reply.
Do you know how tmloadcf identify that descriptor 0 is associated with a
terminal?
Is it possible to write some code that can emulates this situation?
Regards,
Amnon -
Need Example on calling a unix shell script from oracle stored procedure
Hi
Can anybody give example on how to call unix shell script from an Oracle stored procedure. Please give a small example on how to do this .I need this urgently please.
Have a nice time.
Thanks & Regards
JogeshIf you are on 10g you can also use DBMS_SCHEDULER. See Re: Excute Unix command Using PL SQL
-
Call a UNIX shell script from an oracle stored procedure
We need to call a UNIX shell script from an oracle stored procedure
i.e. the control should come back to the procedure once the script completes. Can any body help to achieve this ?There are various ways in achieving this.
For Example, you can call a PRO*C-Library residing on the database server.
This requires a PL/SQL library to be generated and some changes to the Listener configuration.
It is also possible to implement a java procedure on the database being invoked by a PL/SQL wrapper class.
In this way (and if used right) there is also granularity regarding the filestructure permissions given and it may be called during a Forms or other PL/SQL session.
The article below explains a more generic approach how to invoke shell commands from within an Oracle Instance.
Be careful with this, because it really works ;)
Refer to :
http://www.oracle-base.com/articles/8i/ShellCommandsFromPLSQL.php
Message was edited by:
user434854 -
Controlling a procedure execution from a UNIX shell script
I want to control the execution of a PL/SQL procedure from a UNIX shell script.
Below, I include the script.
The control variable which should recive the return of the procedure, dosen't work well.
I want to control the return, because I wanr to make a UNIX script to control the execution of
a load data process with some Oracle procedures.
#!/bin/ksh
echo "Executing procedure pl/sql"
SQLPLUS="sqlplus -s /"
ESQUEMA="esquema1"
echo "\
call ${ESQUEMA}.Z_PROC_PRUEBA();" | $SQLPLUS
echo "Controlling pl/sql execution"
var_err=$?
if [ $var_err -gt 0 ]
then
echo "Error executing pl/sql"
else
echo "pl/sql finished sucessfully"
fiThis is not oracle problem. You can try something like this in your shell program ->
DEV=Udev01/1ods@ODS1
DEV_ID=`sqlplus -s ${DEV} <<!
set heading off feedback off verify off
set serveroutput on
@/prod/ods/satyaki/prac/ctl_build.sql '$1' '$3'; -- If you sql needs to pass argument
exit
!`
O_DIV_ID=`echo $DIV_ID | tr -s " " | sed 's/^[ ]//g'`
if [[ $O_DIV_ID -ne 0 ]]; then
echo "Successfully EXecuted.."
else
echo "Failed..."
fiHope this will help.
Regards.
Satyaki De. -
How to pass arguments to a Unix shell script from PL/SQL?
We want to run a Linux shell script from PL/SQL (10g). This is our code to run the script only and it works fine.
dbms_scheduler.create_job
job_name=>'RUN_LINUX_SCRIPT_' || v_job_name,
job_type=>'EXECUTABLE',
job_action=>'/vol0/FileLoadDir/Bank/DATA_FILES/spell_check.sh',
enabled=>TRUE,
auto_drop=>FALSE
);Now we have a requirement to pass 2 arguments to the .sh file. In the .sh file the 2 arguments are defined as $1 and $2.
I used this method.
dbms_scheduler.create_job
job_name=>'RUN_LINUX_SCRIPT_' || v_job_name,
job_type=>'EXECUTABLE',
job_action=>'/vol0/FileLoadDir/Bank/DATA_FILES/spell_check2.sh',
--job_action=>'/vol0/FileLoadDir/Bank/DATA_FILES/spell_check2.sh /vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt /vol0/FileLoadDir/Bank/DATA_FILES/abcdefghij.txt',
--job_action=>'#!/bin/bash spell /vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt > /vol0/FileLoadDir/Bank/DATA_FILES/abcde.txt',
number_of_arguments => 2,
enabled=>FALSE,
auto_drop=>FALSE,
comments => 'Testing by Channa'
DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE (
job_name => 'RUN_LINUX_SCRIPT_' || v_job_name,
argument_position => 1,
argument_value => '/vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt');
DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE (
job_name => 'RUN_LINUX_SCRIPT_' || v_job_name,
argument_position => 2,
argument_value => '/vol0/FileLoadDir/Bank/DATA_FILES/abcdefghij.txt');
DBMS_SCHEDULER.enable (name => 'RUN_LINUX_SCRIPT_' || v_job_name);But I get an error saying:
STANDARD_ERROR="/vol0/FileLoadDir/Bank/DATA_FILES/spell_check2.sh: line 4: read: `/vol0/FileLoadDir/Bank/DATA_FILES/ebill2.fmt_form_strings_.txt': not a valid identifier
/vol0/FileLoadDir/Bank/DATA_FILES/spell_check2"Check this post:
pass parameter from PL/SQL to Unix "as is" -
Unix Shell Scripts with Oracle
Any body who can give me the link where I can find the Unix Shell Scripts to access the Oracle database and execute the stored procedures and cursors.
Your unix script will contain (at appropriate places):
sqlplus -s username/pasword@server @your_sql_Script_that_calls_the procedure.SQLor
sqlplus -s / @your_sql_Script_that_calls_the procedure.SQL -
Want to create unix shell script for Clone procedure in 11i and r12
Want to create unix shell script for Clone procedure in 11i and r12 .Can anyone help me on this as I m new to oracle apps and scripting.
Thanks in advance .user11958935 wrote:
Thanks but I want it for application cloning ie adcfgclone and autoconfig etc .Please see old threads for similar topic/discussion.
https://forums.oracle.com/forums/search.jspa?threadID=&q=Automate+AND+Rapid+AND+Clone&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
https://forums.oracle.com/forums/search.jspa?threadID=&q=Automate+AND+AutoConfig&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
Thanks,
Hussein -
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
Maybe you are looking for
-
Cant figure out how to play a movie clip on mouseover
Hey guys, I'm a web designer who is wanting to add a touch of flash to his page. I just created a new site that hasnt launched yet. The scene is a city scape with water beneathe. In the water I want to have a fish that bobs up and down slightly on mo
-
Word template with web service - style and font not considered
Hi experts. I'm using a word template with a web services. So i've added my xml tags in the template and i've tried to change the font and style but when i launch the document, what i have defined is never considered. For example if i set in a table
-
Problem with Filtering Data by Using "Greater Than" in APD
Dear Experts, First of all, I am a novice of SAP Data Mining. I try to filter data in APD by using the 'Restrict Amont of Data (the Filter Icon).' My problem is really simple. I don't know how to filter data which have value greater than a constant
-
How to handle a redirect on a Lotus notes DB
Hi everyone, I have a problem, I am connectin to a lotus notes database to download a file (using URLConnection) ...gbp.nsf/agWebLAL?OpenAgent&UNID=A9D19EDE65447DF5C1256F2000465E87 The thing is lotus notes doesn't give the filename, it redirects me t
-
SQL Server 2005 64-bit & SQL CLR Stored Procedures using DI API. COM Error.
Hi, We've created a set of SQL CLR Stored Procs in C# .NET which use the DI API to import data into SAP (DEV was carried out on 32-bit environment). The DLLs and Interop.SAPbobsCOM have been successfully deployed as assemblies on SQL Server with thei