Passing unix variable to oracle parameters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing unix variable to oracle parameters
# 8  
Old 04-08-2010
It would be great if you could tell us what it was actually doing wrong instead of just saying it's not working. When I try your code(modified slightly to just print the query) it seems to work fine:

Code:
#!/bin/bash

file_cnt=31337
cat << EOF
select count(1) into :t_cnt from $2;
insert into t_table(f_name, t_name, f_cnt,loaded) values
('$1','$2',$file_cnt,:t_cnt);
commit;
exit;
EOF

Code:
$ ./sqlplus.sh a b
select count(1) into :t_cnt from b;
insert into t_table(f_name, t_name, f_cnt,loaded) values
('a','b',31337,:t_cnt);
commit;
exit;

Is the highlighted portion what the actual query should be? If not, what do you want the query to be?
# 9  
Old 04-08-2010
You need to declare the t_cnt bind variable before you can use it:

Code:
var t_cnt number

You need to do that before the SELECT statement.
# 10  
Old 04-08-2010
Isn't the Oracle error message self-explanatory ?
You did not declare the bind variable, and you expect Oracle to figure out what "t_cnt" is !!

Also, since you are using PL/SQL syntax, you'll have to use "exec" or "execute" or "begin ... end" block structure around your SELECT statement.

HTH,
tyler_durden
# 11  
Old 04-08-2010
Now. there is no error msg. But value is not inserted.
Code:
file_cnt=`wc -l $1 | awk '{print $1}'`
sqlplus -s  uname/pwd@dbins << EOF
var t_cnt number;
select count(1) into :t_cnt from $2;
insert into t_table(f_name, t_name, f_cnt,loaded) values ('$1','$2',$file_cnt,:t_cnt);
commit;
exit;
EOF

Output is:
Code:
  COUNT(1)
----------
      3448


1 row created.


Commit complete.

# 12  
Old 04-08-2010
Quote:
Originally Posted by Jairaj
Now. there is no error msg. But value is not inserted.
...
That's because you are using PL/SQL syntax in sqlplus without the PL/SQL block structure.

tyler_durden
# 13  
Old 04-08-2010
Any idea,, How do insert this value?
# 14  
Old 04-08-2010
Quote:
Originally Posted by Jairaj
Any idea,, How do insert this value?
By using PL/SQL block structure around your SELECT statement.

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Passing output parameter(Oracle) to variable in ksh Script

Hello, I have researched and tried many way to pass OUT parameter to be stored in variable in KSH Script.Still not success, please help. Here is my Store Procedure. create procedure testout3(v_in varchar2,v_out OUT integer) as begin v_out := 1; end; Here is my testvout.ksh #!/bin/ksh... (1 Reply)
Discussion started by: palita2601
1 Replies

2. Programming

Remote login UNIX box from java passing parameters to the custom script called in the profile

Hello Good Day / Guten Tag.... I have to login the server and the user profile contains some scripts which need the inputs to be taken from the keyboard. So I use the method to conn.authenticateWithKeyboardInteractive(username, new InteractiveCallback() { public String... (1 Reply)
Discussion started by: Sanalkumaran
1 Replies

3. Shell Programming and Scripting

Passing variable from file to Oracle

cat a1 scott robert tom test script : #!/usr/bin/ksh for NAME in `cat a1` do VALUE=`sqlplus -silent "nobody/bobody01@testq" <<END set pagesize 0 feedback off verify off heading off echo off select username from dba_users where username=upper('$NAME'); END` if ; then echo... (3 Replies)
Discussion started by: jhonnyrip
3 Replies

4. Programming

Oracle Variable Passing Test

Hi, I am trying to get the oracle variables and pass the values in sql placed in procedure. VARIABLE vstat='ASDS,FGDS,VCGD,VCXC' Query : select distinct dept from College where section in ('C','D') AND CODES ='' AND NAMES IN ('RAJ','SAM'); I want CODES values to be taken from vstat... (1 Reply)
Discussion started by: Perlbaby
1 Replies

5. Shell Programming and Scripting

Passing Variable Parameters (C shell)

I am trying to execute a copy command via shell script. However, on occassion, 2 or more files need to copied. How do I code for the multiple arguments? Does it matter how the files are delimited? Example: I have a script to copy files from 1 dir to another called duplicate.csh In most... (1 Reply)
Discussion started by: CKT_newbie88
1 Replies

6. Shell Programming and Scripting

Passing wildcard parameters to find via a variable

I have a script to fix permissions which is made up of blocks like: FS_ROOT=/home/shared/Photos FS_EXCLUDE=( \( -path */.webviews -o -path */.thumbnails \) -prune -o ) find $FS_ROOT ${FS_EXCLUDE} -type d -not -perm 2770 -exec chmod 2770 "{}" \; That fragment works as expected, but no matter... (3 Replies)
Discussion started by: mij
3 Replies

7. Shell Programming and Scripting

passing variable to oracle procedure

using the script below I want to pass a parameters thorugh my sql call(@/unixsxxx/xxxx/helpenv.sql emptab ) as input into an oracle procedure xxxx_package.proc1(%1,emptab); . I tried %1 but it does not work. Any suggestions. #!bin/ksh set -x # export... (0 Replies)
Discussion started by: TimHortons
0 Replies

8. Shell Programming and Scripting

Passing parameters form unix to Oracle procedure

Hi, I have screen which was desined in PL/SQL Catridges in apps. In that screen some enterable fields these values r the passing parameters to create value sets, functions, menus etc in apps by using front end screens. Now in that screen i have a button. when i click that button it have to... (0 Replies)
Discussion started by: rajasekharamy
0 Replies

9. Shell Programming and Scripting

passing oracle parameters back to Shell

Hi All, Does anyone have any solutions for passing back multiple variables back to the SHELL from a call to an ORACLE procedure: eg #username='scott' #password='tiger' #database='orcl' username='ITGCD03D03' password='tC5epIew' database='ITGCD03D' sqlplus -s... (4 Replies)
Discussion started by: satnamx
4 Replies

10. Shell Programming and Scripting

Passing arrays to oracle from unix

Hi all Iam trying to send an array to oracle procedure from unix. Iam writing a program in K Shell to pass this array to oracle. Is it possible. Please advice thanks Krishna (7 Replies)
Discussion started by: krishnasai
7 Replies
Login or Register to Ask a Question