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
Rajan
Yes, 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.
Similar Messages
-
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 -
Debugging a program being called from a shell script
hi All,
i want to know how debug a C program being called from A Shell Script,
my script looks like the following :
ecReqProcMain $Cfg/ecReq.g $TotCnt 2>> $ErrFilei also have to pass some arguments to the script itsellft, which in trun going to pass it to the program,
also in some cases i may be required to Pipe some data to the program, like the folowing
cat DataFile | myProgramThanks ,You can also use ss_attach with the scheme that Anton
suggested above. Instead of inserting "dbx" into your
script, insert "ss_attach" into your script.
It's also possible to change your script to something like this:
cat DataFile | ${DEBUG} myProgram
Then you can run your script like this:
setenv DEBUG ss_attach
ecReqProcMain $Cfg/ecReq.g $TotCnt 2>> $ErrFile
--chris -
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. -
Calling linux / unix shell scripts from APEX
Hi -- I'm doing some prototyping, and would like to try calling a unix shell script on the server from within APEX.
Is this possible? Maybe thru Javascript? Other ways? Not sure if it's possible thru pl/sql.
FYI, I'm attempting to check username/password specified at login to see if it's a valid login
to another database (also specified at login). If there's an easier way to do this, I'd love to hear it!
We're highly motivated to have a single apex app work on multiple databases -- largely because of a lack of
administration resources on the other databases. All databases are accessible via database links from
the apex server (the links are necessary to implement other business rules), and I know I can get
the DML working. Powers that be prefer that Database Account authentication (or a facsimile thereof)
be used. I suspect I'm opening myself up to lots of criticism by disclosing this ... :)
Thanks for any ideas,
CarolR -- If I understand you correctly, a pl/sql process in APEX could invoke a java program on the server. Is that correct?
If so, is there any reason it couldn't just call a unix shell script? Seems they're both just executables recognized by the OS....
I know I called unix scripts from embedded sql a billion years ago, but don't recall the method for doing that. What is
the syntax I'd use in apex / pl/sql?
thanks,
Carol -
Calling an external shell-script?
Hello everybody,
I only have a short question: How can I easily call an external shell-script in PL/SQL? I need this to make new directories ...
thx for helpRe: is ADF free??
We have a problem when we want to create a portlet base on WebClipping Port
How to customize login page in 11.5.10.2? -
Calling an external shell script program from ABAP.
Hi,
Can i call an external shell script program from abap which is there on application server.
The FM WS_EXECUTE i know can be used for calling this purpose.
But i am getting a doubt that how can i call the external program from there.
Please clear my doubts.
Thanks in advance.
Vikashsearch in SCN for sm49 and sm69 Tr. you will surely find solutions for it, with a simple search.
-
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 -
Getting an exit value from a program called thru a shell script
how do i get the correct exit value always from a program called thru a shell script
the getExitValue of the process works fine someitmes but not always ...
Ex: write a pgm which sleeps for 5 secs & returns with exit(100).try to invoke this thru a script & try to run this script from Runtime.getRuntime.exec(..)
...the exit value is not same as 100.(it works if the sleep is not given though !!)
can nebody help??ive done that ...see the sample code for ex..
public void execute()
try{
Process program=Runtime.getRuntime().exec(cmd);
printOutput(program.getInputStream());
try
program.waitFor();
catch(InterruptedException e)
System.out.println("Command Interrupted: " + e);
System.out.println("Error status : "+program.exitValue());
catch(SecurityException e)
System.out.println("Error executing program "+e);
catch(IOException e)
System.out.println("Error executing program "+e);
.... -
Problem while calling concsub from shell script
Hi All,
I am facing problem when I am trying to run CONCSUB utility from shell script.The same works well when I try it from command line.The only prob I am facing from shell script is assigning values to temporary variables.
This is how my script looks
#!/bin/bash
export PARM5="$5"
export PARM6="$6"
export PARM7="$7"
echo "INTPARM5=\"$PARM5\""
echo "INTPARM6=\"$PARM6\""
echo "INTPARM7=\"$PARM7\""
echo $FND_TOP/bin/CONCSUB $1 ONT 'Order Management Super User, Vision Operations (USA)' $3 WAIT=Y CONCURRENT ONT $PROGRAM "$INTPARM5" "$INTPARM6" "$INTPARM7"When I try to run the above shell based concurrent program it doesn't pass the parameters as expected and it errors out saying "Wrong number of arguments to call the procedure"
I tried my luck from some of the previous posts ({thread:id=2360776} ),but to vain
If anyone has any ideas,please suggest!!
Thanks in advance!!
Edited by: sandy on May 4, 2013 12:54 PMHere are your proofs
Proocedure
PROCEDURE abc(--p_errbuf OUT VARCHAR2,
--p_errcode OUT VARCHAR2,
p_order_no IN NUMBER DEFAULT NULL,
p_customer_id IN NUMBER DEFAULT NULL,
p_name IN VARCHAR2 DEFAULT NULL
IS
v_cname VARCHAR2(200);
v_ordered_date DATE;
v_order_number NUMBER;
v_order_type VARCHAR2(200);
BEGIN
fnd_file.put_line(fnd_file.output, 'Begin Execution');
SELECT DISTINCT ac.customer_name,
d.ordered_date ordered_date,
d.order_number order_number,
x.NAME order_type
INTO v_cname
,v_ordered_date
,v_order_number
,v_order_type
FROM oe_order_headers_all d,
oe_transaction_types_tl x,
wsh_delivery_details b,
wsh_delivery_assignments c
,ar_customers ac
WHERE 1 = 1
AND ac.customer_id = b.customer_id
AND d.order_type_id = x.transaction_type_id
AND x.LANGUAGE = 'US'
AND b.released_status = 'B'
AND b.source_header_id = d.header_id
AND c.delivery_detail_id = b.delivery_detail_id
AND d.order_number=NVL(p_order_no,d.order_number)
AND ac.customer_id = NVL(p_customer_id,ac.customer_id)
AND x.name=NVL(p_name,x.name)
AND NOT EXISTS (SELECT 1
FROM wsh_delivery_details b
WHERE 1 = 1
AND b.released_status != 'B'
AND b.source_header_id = d.header_id)
--BETWEEN ('1213794') and ('1213797'))
AND rownum<2;
INSERT INTO xxc_temp(customer_name,ordered_date,order_number,order_type) VALUES(v_cname,v_ordered_date,v_order_number,v_order_type);
COMMIT;
fnd_file.put_line(fnd_file.output, 'Order Number is' || v_order_number);
fnd_file.put_line(fnd_file.output, 'Order Type is' || v_order_type);
END;Script
#!/bin/bash
set -x
export PARM5="$5"
export PARM6="$6"
export PARM7="$7"
sqlplus -s $1 <<EOF
set head off feed off serverout on size 1000000
exec abc('$PARM5','$PARM6','$PARM7');
exit
EOFNow when I run the 'XX Order Detail CSV Report' I get the below log and no Output
+---------------------------------------------------------------------------+
Application Object Library: Version : 12.0.0
Copyright (c) 1979, 1999, Oracle Corporation. All rights reserved.
XXKES_PDF_TRANSFER module: XX Order Detail CSV Report
+---------------------------------------------------------------------------+
Current system time is 06-MAY-2013 05:05:56
+---------------------------------------------------------------------------+
+ export PARM5=66432
+ PARM5=66432
+ export PARM6=
+ PARM6=
+ export PARM7=Mixed
+ PARM7=Mixed
+ sqlplus -s APPS/APPS
+---------------------------------------------------------------------------+
Executing request completion options...
Output file size:
0
+------------- 1) PRINT -------------+
Disabling requested Output Post Processing. Nothing to process. The output of the request is zero byte.
+--------------------------------------+
Finished executing request completion options.
+---------------------------------------------------------------------------+
Concurrent request completed successfully
Current system time is 06-MAY-2013 05:05:56
+---------------------------------------------------------------------------+After the concurrent program executed I queried the table xxc_temp and here you see the data
SQL> select * from xxc_temp;
CUSTOMER_NAME
ORDERED_D ORDER_NUMBER ORDER_TYPE
A. C. Networks
18-FEB-13 66432 MixedMy procedure fetches the data fro given set of i/p parameters but it doesn't give o/p coz it's a host based conc program.Please advise if there's a way to get the o/p in a host based conc program
Thanks!! -
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. -
How to get return code or parameters from PL/SQL in my shell script ?
My shell script must check the result of PL/SQL's running, and decide what to do in the next step.
I think you put the problem the wrong way.
You should try to do as much as possible through your SQL scripts, and, if you need to make OS calls, you may do that using host(command_string).
If you need to transfer parameters from other programs to your FORMS (PL/SQL), then you have to see user_exit.
Some other means would be to have your PL/SQL write to certain OS files that the shell script may read, but that doesn't seem like good practice to me. -
Starting and stopping an SQL query from within a Shell script
DB version:10gR2
OS Version:AIX
We have a C++ application called WpnCreate.cpp, which is causing some locking problems.
So, we have decided to capture(using SPOOL) the locking info(session info, blocking program,..etc) using an SQL query.
WpnCreate.cpp program is initiated by a shell script. So we need this SQL query(.sql) to start firing just before WpnCreate.cpp is called and when WpnCreate.cpp has finished executing, we need the SQL query execution to stop.
But how do i stop the sql query execution? Should i capture the session id and serial# of this session and use kill -9 at the end of the shell script?
Flow of the Shell script should be like this
Step1. Start firing the SQL query which captures the locking info and SPOOL them to a file
Step2. Execute WpnCreate.cpp program
Step3. Stop the firing of SQL query once WpnCreate.cpp has finished executing ( i don't know how)How will i go about achieving this?How can you run your step 2 untill & unless your step 1 gets over. You can run in background but then it will not capture the correct information.
I think you need to run your step 1 after step 2 , then only you will be able to capture the information.
You can run your C++ program in background and can wait for some time using sleep command and then run the query to check the locking information. -
Passing parameters with spaces to SCCM Run PowerShell Script task
I am working on an OS deployment task sequence in SCCM 2012 R2 with several Run PowerShell Script tasks. Most of them run fine, but I am having trouble with the one I need to pass parameters to.
The parameters I need to pass are:
-ComputerOU "ou=All Workstations,dc=contoso,dc=com" -GroupDN "cn=Group1,ou=All Groups,dc=contoso,dc=com"
I have that line (with actual DNs) entered in Parameters of the task.
But when the script runs on the target machine, the values of the parameters in the script are truncated at the spaces. $ComputerOU is set to "ou=All" and $GroupDN is set to "cn=Group1,ou=all"
What syntax should I be using the Parameters field of the Task in order to properly pass PowerShell parameter string values that include spaces?
Tim Curwick
MadWithPowerShell.comThank you, TC, but I am not calling the parameters from within PowerShell.
The parameters are in the settings of a task sequence task to be used by the task to launch a script. The syntax I am using would be correct for use within PowerShell or from a command line or batch script, but SCCM appears to be doing some parsing
before or while it is passing them to the script, possibly dropping the quotes which causes mishandling of the spaces in the string values.
Historically, it is always challenging to give one application parameters to pass to another application, and the required syntax can get quite tricky when the two application handle quotes or spaces differently, or when the parent application wants to parse
something intended to be passed on as is to the child application.
I'm sure someone has already figured out what the syntax needs to be for doing this with an SCCM 'Run PowerShell Script" task, it's just one of those issues that is hard to Google effectively.
Any other ideas?
Tim Curwick
MadWithPowerShell.com -
Query not running in shell scripting
Hi Experts,
I have created a query to check the temp tablespace usage in production servers and i wanted to run the query using shell scripting but when i running the query in the script i am not getting any errors or output i am unale to rectify where exactly i am doing mistake
below is the query
SELECT A.tablespace_name "tablespace", D.gb_total, ROUND(SUM (A.used_blocks * D.block_size) / 1024 / 1024/1024,2) "gb_used", ROUND(D.gb_total - SUM (A.used_blocks * D.block_size) / 1024 / 1024/1024,2) "gb_free" FROM v$\sort_segment A, (SELECT B.name, C.block_size, ROUND(SUM (C.bytes) / 1024 / 1024/1024,2) "gb_total" FROM v$\tablespace B, v$\tempfile C WHERE B.ts#= C.ts# GROUP BY B.name, C.block_size) D WHERE A.tablespace_name = D.name GROUP by A.tablespace_name, D.gb_total
Please help out in this.
Thanks....two files:
1) file to connect, for example called conection.sql
../../../sqlplus user/password@your_database @../../../../your_script.sql
2) your script in the other file "your_script.sql"
SELECT A.tablespace_name "tablespace", D.gb_total, ROUND(SUM (A.used_blocks * D.block_size) / 1024 / 1024/1024,2) "gb_used", ROUND(D.gb_total - SUM (A.used_blocks * D.block_size) / 1024 / 1024/1024,2) "gb_free" FROM v$\sort_segment A, (SELECT B.name, C.block_size, ROUND(SUM (C.bytes) / 1024 / 1024/1024,2) "gb_total" FROM v$\tablespace B, v$\tempfile C WHERE B.ts#= C.ts# GROUP BY B.name, C.block_size) D WHERE A.tablespace_name = D.name GROUP by A.tablespace_name, D.gb_total;
3) execute --> conection.sql
Maybe you are looking for
-
Shall I just reinstall the program? It was running fine until I got a Trojan last week. I'm pretty sure the Trojan has been removed'
-
FM for adding/deleting partner functions
Hello everyone, Is there an Fm to add/delete partner functions of customer.I am not sure whether sd_partner_single_modify works.Can anyone confirm this or post other FM which does this. Thanks in Advance, Kiran
-
Implementing SAP GRC CC 5.2 - Help with RTAs for SAP 4.0B & 4.6B Needed
We are in the process of implementing the SAP GRC Compliance Calibrator 5.2 across multiple environments including SAP legacy systems. Our key issue is that we cannot find any RTAs for SAP 4.0B and 4.6B. I am positive that someone has done this some
-
How do I stretch content Vertically in a WebCenter Spaces page?
I have a box at the bottom of my page with a document explorer inside. I need to have it stretch as the page stretches vertically. Can anybody help? Thanks
-
Ssh won't save passphrase in keychain
When I type ssh in Terminal, I get prompted for my passphrase, and it properly connects when I enter it. However the prompt is always a text prompt in Terminal instead of the graphical prompt, and my passphrase is never saved, in the keychain or any