Passing Shell array to SQLPlus


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing Shell array to SQLPlus
# 15  
Old 12-12-2011
Quote:
Originally Posted by roby2411
...but there is another issue now. using this way will use the sql bind variables.
I still need to use bind variables from oracle to execute a pre defined shell array...
So what's the issue?

tyler_durden
# 16  
Old 12-25-2011
Using this way
echo "SELECT ename from emp where empno = $i;"'\n'will pass the empno as value, I was looking to pass it as sql bind variable which looks like
echo "SELECT ename from emp where empno = :SomeId;"'\n'
# 17  
Old 12-26-2011
Quote:
Originally Posted by roby2411
Using this way
echo "SELECT ename from emp where empno = $i;"'\n'will pass the empno as value, I was looking to pass it as sql bind variable which looks like
echo "SELECT ename from emp where empno = :SomeId;"'\n'
Why do you want to do that?

tyler_durden
# 18  
Old 12-26-2011
...
Code:
while (x<4)
loop
exec :deptno := '${FileName[x]}'
select customer_name from customer where customer_id=:deptno;
end loop

You almost got it, just need a sub shell in the here doc:

Code:
$(for i in ${FileName[@]}; do
echo "
exec :deptno := '$i'
select customer_name from customer where customer_id = :deptno;
"
done)

You may need to change $() to `` to get around of a ksh bug.
# 19  
Old 12-27-2011
Tyler_durden, this is requested by the DBA team, using bind Variable is preferred in continuous operation that user variable Bind Variables (I'm posting the link to share the information that might help others Smilie ).

Binlib, using your way is by passing the usage of bind SQL variable and all query that are statically using ( yyy=:xxx ) will be rejected as :xxx is a non accepted value for column yyy

At the end, please let me say thank you for all those are helping here, I'm really learning from your great experiences and new information were added to my knowledge with each single line of code you dropped here to help me.

---------- Post updated at 06:56 AM ---------- Previous update was at 06:47 AM ----------

For those where are not familiar with bin variables this article simply explain why you might use them one time.
Bind variables - The key to application performance
# 20  
Old 12-27-2011
Shell variables can not be used as bind-variables directly. A bind variable is a variable of the accessing application passed to the database. The accessing application in this case is SQL*Plus and not the shell itself. You can use bind variables defined in SQL*Plus as shown in several places in this thread.
Your DBA team gives good advice about bind variables, but there is no way to prepare the statement and then pass the variables when the prepared statement is executed because the shell does not have a mechanism to do so.
Perl or phyton offer support for bind variables and do not need SQL*Plus to connect to the database.
# 21  
Old 12-27-2011
Thank you Cero, I had doubts that there is a way somewhere to do this. but it's clear as there is no way for such actions.
Would like to thank all participants once again, Thank You!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing string from bash to sqlplus

Hello, I have file (PARFILE) with string on first line: INCLUDE=SCHEMA:"IN\( 'SCHEMA1','SCHEMA2','SCHEMA3' \)"In .sh script I use: .... IMPORT_SCHEMA=`awk 'NR==1{print $2}' ${PARFILE}` ...print $2 is because 'SCHEMA1','SCHEMA2','SCHEMA3' is 2nd column in file echo "$IMPORT_SCHEMA"... (5 Replies)
Discussion started by: DjukaZg
5 Replies

2. Shell Programming and Scripting

Passing Oracle function as file input to sqlplus

Apologies if this is the incorrect forum.There is an issue in the function call I am facing while calling the same from a unix shell scripts. Basically, I want the ref cursor to return values to a variable in sqlpus. The function call is currently saved in a ".txt" file in a unix location. I want... (7 Replies)
Discussion started by: amvip
7 Replies

3. Shell Programming and Scripting

Passing sqlplus output to shell variable

Hi , I am using below code : for i in `ps -ef|grep pmon|awk {' print $8 '}|cut -f3 -d'_'|grep -v '^grep'` do ORACLE_SID=$i export ORACLE_SID; dest=`sqlplus "/ as sysdba" <<EOF set heading off feedback on verify off select DESTINATION from v\\$archive_dest where target in... (5 Replies)
Discussion started by: admin_db
5 Replies

4. Shell Programming and Scripting

Passing a parameter from a shell script to sqlplus

Hi All, I'm new to Linux and scripting, apologies in advance for 'stupid' questions. Please help... Im writing a script that calls a sqlplus script but the sqlplus requires inputs and i cant seem to get this to work. here is my code. #!/bin/sh TERM=vt100 export TERM... (4 Replies)
Discussion started by: Mahomed
4 Replies

5. Shell Programming and Scripting

Shell Script passing parameters to sqlplus code

Hello All, I am interested in finding out a way to pass parameters that are entered at the prompt from HP unix and passed to SQLPlus code with a Shell Script. Is this possible? Thanks (4 Replies)
Discussion started by: compprog11
4 Replies

6. Shell Programming and Scripting

Passing a file handler and an array from Perl to Shell Script

Hi there, I am trying to call a shell script from a Perl script. here is the code: @args = ("sh", "someshellprg.sh", "a file handler", "an array"); system(@args) == 0 or die "system @args failed: $?"; in the shell program, I examine if the arguments exits using: if then echo... (5 Replies)
Discussion started by: pinkgladiator
5 Replies

7. Shell Programming and Scripting

Passing the unix variable to sqlplus

Hi, I am writing a script which creates an external table using a shell script. My requirement is like this. Usage: . ./r.ksh <table_name> - this should create an external table. e.g . ./r.ksh abc - this should create an external table as abc_external. How do i achieve this? Please... (5 Replies)
Discussion started by: Anaramkris
5 Replies

8. Shell Programming and Scripting

error in passing a variable to sqlplus from a shell script

hi, I am using a shell script from where i will be conecting to sqlplus.. i am having a problem in passing a variable to sqlplus query.. i will be assigning the variable in the unix environment..whenever i am trying to pass a variable having the contents greater than 2500 characters, i am... (3 Replies)
Discussion started by: kripssmart
3 Replies

9. UNIX for Advanced & Expert Users

passing unix variable to sqlplus without a file name

Hi, I want to input unix variable to sqlplus.The following is working fine sqlplus username/password @dummy.sql param1 param2 << EOF create user $1 identified by $2; EOF But I dont want any file name to be passed,I just want to pass the parameter. Is there any way to that?? Thanks... (3 Replies)
Discussion started by: sakthi.abdullah
3 Replies

10. Shell Programming and Scripting

passing parameters from a shell script to sqlplus

Hi , I want to pass parameters from a shell script to a sql script and use the parameter in the sql query ..and then I want to spool a particular select query on to my unix box... for 4 different locations by writing only one sql script Right now no file is generated on the unix box...it is a... (2 Replies)
Discussion started by: phani
2 Replies
Login or Register to Ask a Question