problem to run sql startment in script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers problem to run sql startment in script
# 1  
Old 08-22-2007
problem to run sql startment in script

Hello,
I have a script to run a list of customer information, but it not work. can anyone help below:

echo "Please input list to check customer detail:"
read list
for file in 'cat $list.txt'
do
echo "select cuname as "FROM CUNAME", invo_num as "RECS", total_amount as "AMOUNT", tax_amount as "TAX", CUSTOMERNAME as "INTO CUSTOMER", status, original_amount from cuname_2 where CUNAMEin '$file' ;"|sqlplus4 >> output.txt
done

The list look like:
John
Marry
peter
tom

The script cannot read the list correctly.....Smilie

Thank you.
# 2  
Old 08-22-2007
I think you have to escape all the quote characters inside the statement:

Code:
echo "select cuname as \"FROM CUNAME\", invo_num as \"RECS\", total_amount as \"AMOUNT\", tax_amount as \"TAX\", CUSTOMERNAME as \"INTO CUSTOMER\", status, original_amount from cuname_2 where CUNAMEin '$file' ;"|sqlplus4 >> output.txt

# 3  
Old 08-22-2007
Quote:
Originally Posted by robotronic
I think you have to escape all the quote characters inside the statement:

Code:
echo "select cuname as \"FROM CUNAME\", invo_num as \"RECS\", total_amount as \"AMOUNT\", tax_amount as \"TAX\", CUSTOMERNAME as \"INTO CUSTOMER\", status, original_amount from cuname_2 where CUNAME in '$file' ;"|sqlplus4 >> output.txt

It's still not work.Smilie
nothing in the output.txt
If I just copy the startment below, it work ok.

echo "select cuname as \"FROM CUNAME\", invo_num as \"RECS\", total_amount as \"AMOUNT\", tax_amount as \"TAX\", CUSTOMERNAME as \"INTO CUSTOMER\", status, original_amount from cuname_2 where CUNAME in 'Tom';"|sqlplus4 >> output.txt

so, it look like cannot read the file correctly.

ANY HELP?????!!!Smilie
# 4  
Old 08-22-2007
does the value in list variable read through "read statement"
contains another list of files or it just contain values ?
# 5  
Old 08-22-2007
Quote:
Originally Posted by matrixmadhan
does the value in list variable read through "read statement"
contains another list of files or it just contain values ?
I will input the list filename.
For example: the filename is "customer.txt" and it contains the following:

Tom
John
Marry
Peter
# 6  
Old 08-22-2007
anyone can help????
# 7  
Old 08-22-2007
shouldn't this
Code:
for file in 'cat $list.txt'

be using BACK-quotes/ticks:
Code:
for file in `cat $list.txt`

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

run sql queries from UNIX shell script.

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX? :confused: (1 Reply)
Discussion started by: 24ajay
1 Replies

2. UNIX for Dummies Questions & Answers

Script to run sql query.

Please read How To Ask Questions The Smart Way (1 Reply)
Discussion started by: balu_279013
1 Replies

3. Shell Programming and Scripting

Run sql script and send to mail if not empty?

Thanks again for helping me out. I was wondering if anyone else has encountered this issue. I have a SQL script that produces a list -however we are only interested in that list if the length is not zero Here is the sql file named dailyBalance.sql select * from Balance where... (1 Reply)
Discussion started by: Astrocloud
1 Replies

4. Shell Programming and Scripting

Time taken to run a SQL script

Hello I am asked to run around 5-6 SQL queries in a shell script and take a note of the time taken to execute each query to a file. How do I get the time taken to run the individual SQL queries (2 Replies)
Discussion started by: vat1kor
2 Replies

5. 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

6. Shell Programming and Scripting

Run Sql plus in shell script

Hello, I want to connect to ssh, run a query, and store that into a variable in the shell script. Also I need to pass the variable back to php to display the query results. I have created a public/private key pair for ssh connection and that is working fine. Also I am able to run query in the... (8 Replies)
Discussion started by: shekhar2010us
8 Replies

7. Shell Programming and Scripting

run sql query via perl script

Hello, If I run this command on the server it works. # dbc "update config set radio_enabled = 0;" how can I execute the same command in perl. I have defined the dbc path. Can any one please correct the last line. #!/usr/bin/perl #database path $dbc='/opt/bin/psql -Userver... (0 Replies)
Discussion started by: sureshcisco
0 Replies

8. Shell Programming and Scripting

shell script to run .sql files

hi Friends, Please help me in writing shell script to run list of sql files. database is Oracle 9i, unix os is solaris Requirement is 1. sql file must take two inputs a)feed id and b)business date 2.shell script must out put .xls or .csvfile as out put without trimming any column name and... (1 Reply)
Discussion started by: balireddy_77
1 Replies

9. Shell Programming and Scripting

How to run an SQL script inside a shell

How do I create a K Shell which would silently (without user input) logon to Oracle and run an SQL script? Any help will be greatly appreciated. Steve (1 Reply)
Discussion started by: stevefox
1 Replies

10. Shell Programming and Scripting

can nested SQl be run in Unix Script?

can nested SQl be run in Unix Script? I tried some and found only simply sql(one select) can work well in unix script. (21 Replies)
Discussion started by: YoYo
21 Replies
Login or Register to Ask a Question