Passing variable from file to sql from script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing variable from file to sql from script
# 8  
Old 11-03-2014
If installed on your system, read man paste.
# 9  
Old 11-03-2014
Quote:
Originally Posted by pallvi_mahajan
but how i can call this in .sql, how $filecount replace in .sql file
Code:
select * from tablename where acc in (
45456546456, 45464564565, 67854353454, 67657612132)

how are you trying to use it?
That sql you provided doesn't have any "line counts" .. so where do you want to use the line count in that query ?

[edit]
oh wait ..

just noticed you changed your question part way through and I missed it Smilie

Quote:
where acc in ( all records which are in acc.txt)
that gets a lot trickier ... Smilie

I'd probably use an external table pointing to the file, then just join with that table ... Are you using ORACLE ? or some other DB ? External tables are Oracle, other DB may have other tools for loading/peeking into files ...

[/edit]
# 10  
Old 11-03-2014
i have oracle

---------- Post updated at 04:03 PM ---------- Previous update was at 03:51 PM ----------

Hi Ditto,

We have passed $file_count variable to .sql file.

what does this command do

ln_input number := nvl('&1',0);
# 11  
Old 11-03-2014
Quote:
Originally Posted by pallvi_mahajan
i have oracle
In that case, this becomes an Oracle related question, not Unix related one Smilie

Read up on External tables here:

Tables and Table Clusters

You can see an example of an external table here:
CREATE TABLE
and the full syntax is on that page.

Further questions should probably go into an Oracle forum, not a Unix one Smilie

Good luck!

---------- Post updated at 16:07 ---------- Previous update was at 16:04 ----------

Quote:
Originally Posted by RudiC
If installed on your system, read man paste.
FYI - I don't think it works in Oracle - I just tried, not getting it to work, and it's installed Smilie
# 12  
Old 11-03-2014
Quote:
Originally Posted by pallvi_mahajan
. . .
what does this command do
ln_input number := nvl('&1',0);
nvl provides a "default" value for missing i.e. NULL variables, so if &1has not been assigned to, number will become 0.
# 13  
Old 11-03-2014
Hi All,

am getting confused, please let me know how i can do this

how
in_put number :-nvl('&1',0) can take all values from file.

---------- Post updated at 06:01 PM ---------- Previous update was at 04:17 PM ----------

Hi Ditto,

we have no permission in database to create external table. so is there any alternate way for this
# 14  
Old 11-04-2014
How about starting over, reformulating the request and posting the script and related files?
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 SQL to a BASH script

OS Solaris 10, DB oracle 10g Hello, We currently have a BASH script that runs and moves image files from a remote server to the local db server. A snippet of the code shows that we are picking up all Images that are 'mtime -1' some code... for file in `ssh user@10.200.200.10 'find... (3 Replies)
Discussion started by: JonP
3 Replies

2. Shell Programming and Scripting

Passing variable to sql

How to pass variable to sql file. Im tryin in two ways, Method 1: my.sql select * from table where col1 = '$1' and col2 = 'text'; Method 1execute: dbaccess database my.sql $var Method2: select * from table col1 in (`cat inputfile`) and col2 = 'text'; method... (2 Replies)
Discussion started by: Roozo
2 Replies

3. Shell Programming and Scripting

Passing a string variable from Unix to Sql Plus

Hi Guys, I am trying to pass a string variable from Unix shell script to sqlplus as a parameter. I have tried using single quotes with the variable name but it does not work. Please help me with it. I am using BASH. My code: Your help is much appreciated. Thanks, shil (2 Replies)
Discussion started by: infintenumbers
2 Replies

4. UNIX for Dummies Questions & Answers

SQL Script to use variable value from input file

Here is the requirement, When I run the "run file KSH (sql)", it should substitute '${pCW_Bgn_DT}' with 201120 and '${pCW_End_DT}' with 201124 Input File ---------- $ cat prevwk.dat 201124 20110711 run file KSH (sql) ------------------ In this file, I want to use the variables... (1 Reply)
Discussion started by: shanrice
1 Replies

5. Shell Programming and Scripting

Replace a var in sql file with shell script variable

I have a requirement where i have a sql file (filetext.sql). This file contains a variable ss_code. Now in a shell script im trying to replace the variable ss_code with a value contained in the shell script variable MTK_DC..tried the below in the script MTK_DC="mit,cit,bit" OUT=`awk -v... (4 Replies)
Discussion started by: michaelrozar17
4 Replies

6. UNIX for Advanced & Expert Users

Passing Hash variable in to sql query in perl

Hi Everyone, Can anyone help me how do i call hash variable in to sql query in perl. Please see the script below i have defined two Hash %lc and %tab as below $lc{'REFF'}='V_RES_CLASS'; $lc{'CALE'}='V_CAP_CLASS'; $lc{'XRPD'}='V_XFMR_CLASS'; $tab{'V_RES_CLASS'}='V_MFR_SERS';... (6 Replies)
Discussion started by: jam_prasanna
6 Replies

7. Shell Programming and Scripting

passing arguments to sql script

Hi Gurus, i have one requirement in unix script, i have a file called abc.txt in that few lines are there with the empid, i need to read each line and pass to .sql script. ex: abc.txt 2345 2346 1243 1234 i need to pass these arguments to .sql script rom unix ex: select * from... (1 Reply)
Discussion started by: Devendar
1 Replies

8. Shell Programming and Scripting

Passing argumnets from shell script to sql

hi I all , I have sql statment in my shell script , I pass two argument to the script I need to pass the this two arguments to the sql statment example : runsql.sh "1" "2" sql : updat tables_x set y=0 where A=:x should subsituted by "1" and B=:y shuold subsituted bt "2"... (1 Reply)
Discussion started by: habuzahra
1 Replies

9. UNIX for Advanced & Expert Users

passing value to a variable in a SQL

Hi Folks, This is a small chunk of the bigger problem which i am facing and some help here will help me resolve the rest of the issue. Problem is that i need to pass the value of a variable from a shell script to a SQL query (infact a lot of SQL's) i have the following solution but somehow... (4 Replies)
Discussion started by: kamitsin
4 Replies

10. Shell Programming and Scripting

Passing PL/SQL variable value to Shell Varible

Hi my UNIX Friends, Im calling some SQL scripts through Unix Shell scripting. How do I export the value of PL/SQL variable value into a Unix shell script variable? Also could any one inform me about the 'search' and 'cut' utility of PL/SQL (like 'grep' and 'cut' in Shell scripting). ... (10 Replies)
Discussion started by: ganapati
10 Replies
Login or Register to Ask a Question