Problem in Passing sql query for a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in Passing sql query for a script
# 1  
Old 09-05-2008
Problem in Passing sql query for a script

Unix prompt
=========
echo "Enter the query"
read q
==========

User has entered :
SELECT * FROM employee
=====================
Now the problem starts..

echo $q

Output: SELECT "all files names in the PWD" FROM employee

================================================

Problem is that whenever I am passing a query (The query result should be stored in a variable ) containing '*' and passing the variable to a script
then the in the variable "SELECT 'all files names in the PWD' FROM employee" is stored instead of the actual query "select * from employee " .
How to avoid special meaning of '*'?
Here '\' before '*' is also not working...
plz help...
# 2  
Old 09-05-2008
Do you know about globbing?

either use '*' or use set -f to turn off globbing before you run your shell script
# 3  
Old 09-05-2008
Actually echo "$q" with double quotes prevents the globbing. The value in q does not have the wildcard expanded, it's when you use it without properly quoting it that you get the file names globbed.
# 4  
Old 09-05-2008
I should show the code itself..
echo "enter ur query"
read q

( sleep 1
echo "niroj_p"
sleep 1
echo "*******"
prompt off
echo "`dbaccess db_nm<< EOFSQL 2>> /dev/null/
$q; # line:here I am getting problem
EOFSQL`" > nilu.tmp
sleep 1
echo "exit") | telnet remote_nm

================================
If I will use "$q" as told by era in the error line(shown above in green )then :

+read q
select * from events

+ dbaccess db_nm
+ 0<<
"select * from ods_event";
2>> /dev/null/
=================
Giving error
------------------------------------------------
# 5  
Old 09-05-2008
Thanx jim 'set -f' is working nice
# 6  
Old 09-05-2008
What's the point of the echo around the backticks?

Code:
dbaccess db_nm<<EOFSQL >nilu.tmp 2>/dev/null/
$q;
EOFSQL

I don't get wildcards with this, but you might put double quotes in <<"EOFSQL" if you do.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in passing IFS array to SQL Query

Hi, I have created a shell script that reads line from text file and insert into DB table. I have used IFS to separate the line text. Looks IFS is splitting text properly but while passing one of the values that has special characters in it to query, it is giving weird issue. Below is my... (2 Replies)
Discussion started by: yuvi
2 Replies

2. Shell Programming and Scripting

Passing value of variable to a query within shell script

I have a script in which i connect to database to run a query and get the result of the query to a temp file. This works fine , now what i want is there is flat file which contains the value to be used in the query. I want to read this file line by line and then run the query for each value in that... (7 Replies)
Discussion started by: gpk_newbie
7 Replies

3. Shell Programming and Scripting

Run SQL thru shell script: how to get a new line when run sql query?

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)
Discussion started by: Kapom
2 Replies

4. Shell Programming and Scripting

Problem in formatting output of SQL query in excel sheet in shell script

Hi Guys.. Need your help to format the output of my shell script. I am using spool command to take out put in csv file. below is my code. (for example) col USERNAME for a15 col EMAIL for a30 col FULL_NAME for a20 col LAST_LOGIN for a40 col DATE_CREATED for a40 SPOOL 120.csv... (3 Replies)
Discussion started by: Agupte
3 Replies

5. Shell Programming and Scripting

problem in SQL query

I used the following code code select * from tablename where columnname Instead of printing the expected output it prints all the files in the present directory since there is a "*" in the code. Is there any way to overcome the problem? Thanks Ananth (2 Replies)
Discussion started by: Ananthdoss
2 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 a variable from shell script to mysql query?

I heard this was possible but from my research I haven't been able to figure it out yet. Seems it should be simple enough. Basically from a high level view I'm trying to accomplish... . $X='grep foo blah.log' then 'mysql command SELECT foo FROM bar WHERE ' . $X or something like that. ... (2 Replies)
Discussion started by: kero
2 Replies

9. Shell Programming and Scripting

sql query problem

Hi, I am passing an argument for the script and that argument values should exist in database. bill_period_input="'""$1""'" bill_period=`sqlplus uname/pwd@dbname <<eof! set verify off set heading off set feedback off select bill_period from bill_period_ref where... (4 Replies)
Discussion started by: ss_ss
4 Replies

10. Shell Programming and Scripting

Problem while storing sql query value in a variable

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)
Discussion started by: krishna_gnv
1 Replies
Login or Register to Ask a Question