I created a script to read a csv file with four columns. The script also saved values of each col in a arry.
In the script, i connected to db try to run a query to pull out data baisc on the values from the csv file.
select Num from tableName
where Sec_Num in ('${isin[@]}') /*isin[@] is an arry which its data are from extracted from the csv file.
could you please tell me what wrong with this query. When I run the script,it is unable to pull out any data from db. Do you have any suggestion?
Thanks You!
Last edited by Sherry_Run; 12-11-2007 at 06:21 PM..
select Num from tableName
where Sec_Num in ('${isin[@]}') /*isin[@] is an arry which its data are from extracted from the csv file.
When I run the script,it is unable to pull out any data from db.
First off, a variable in single quotes won't get expanded (in fact this is what single quotes are for - protect variables from expansion). So probably your SQL script wont see the content of $isin[], but the string "${isin[@]}", which, of course, won't be found in the database. To correct this write your SQL statement into an intermediate file and then execute this file. Like here:
Once the script is running you can delete the intermediate file immediately, but for debugging purposes it is good to have a look into into it, which is why i put a comment in front of "rm".
Second (possible) point: I dont know all too much about SQL, but i think a list of values has to be comma-separated. If this is not the case, than this point is moot, but in case this is true the variable expansion "${isin[@]}" would be wrong: the shell expands the array to a space-separated list instead of a comma-separated one. Expand the list prior to using it and put commata in between:
You would have to use the variable "$chList" instead of the array in the first code snippet of course.
Hi
iam new to shell scripting
how to declare variables as redshift query and I have to compare two counts by using if condition .
ex:count=select count(*) from prd;
select count(*) from prd;
select count(*) from tag;
can any one help me .
Please use CODE tags when displaying... (1 Reply)
Hi,
I'm trying to asign to ksh varible some values of a sql query. The output query would be:
xxxx 1
yyyy 2
I do:
values=`$PATH_UTI/query_sh "
select think1||'------'||think2 from some_table
where think3 = '$1';
... (2 Replies)
Hello Experts,
This sounds crazy, but one of my requirements is that if ID in 5th column in my input file (: separated) is not present in the oracle database table (say t_id) then this record should be skipped. I am using awk for all other requirements. So I was thinking if this requirement... (4 Replies)
Hi, this's Pom. I'm quite a new one for shell script but I have to do sql on shell script to query some information from database.
I found a concern to get a new line...When I run my script, it retrieves all data as wondering but it's shown in one line :(
What should I do? I'm not sure that... (2 Replies)
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)
query sql using shell script, is it possible?
my friend told me to do a file.sql and link to my shell script, but can i query sql using shell script?
thanks in advance! (2 Replies)
Hi,
When i execute the below statement , the value is not getting stored in the variable.
AnneeExercice=`sqlplus $LOGSQL/$PASSWORDSQL << FIN >> $GEMOLOG/gemo_reprev_reel_data_ventil_$filiale.trc
SELECT bi09exercice
FROM bi09_scenario
WHERE bi09idfiliale=UPPER('de')
AND ... (1 Reply)
Hi,
My requirement is :
We are calling an sql statement from a UNIX session, and fetching data into some variables from a table .. now we are unable to access these variables from outside the SQL part. Please let me know how can I achieve this.
Can you please share a code snippet which... (4 Replies)
I know htis isnt exactly unix.... but hopefully someone can help me or direct me someplace to get help.
I can run sql queries in scripts against my informix db using:
dbaccess mydb myquery.sql >> sql.output
I need to write my script to select based on todays date. Its very... (5 Replies)