The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Add single quotes in string mrjunsy UNIX for Dummies Questions & Answers 1 07-18-2008 10:09 AM
Double quotes or single quotes when using ssh? password636 Shell Programming and Scripting 3 05-29-2008 08:52 PM
awk to print ' (single quotes) orahi001 UNIX for Dummies Questions & Answers 2 03-11-2008 04:30 PM
echo using single quotes chella Shell Programming and Scripting 3 10-29-2007 12:54 AM
im stuck! 'single quotes' satnamx UNIX for Dummies Questions & Answers 4 03-29-2006 06:44 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 05-08-2009
little_wonder little_wonder is offline
Registered User
  
 

Join Date: May 2009
Posts: 26
Thumbs up How can i use single quotes for SQL command in shell script

Hi.

please help me to write the following query in a shell script.

the Query is :select no,salary from emp_info where name='$var_name'

the following is my code.

#! /bin/sh

var_name=$1

sqlplus -s user/pwd@DB << EOF

select no,salary from emp_info where name="'$var_name'";

exit

EOF

Note: I can use the code for the number comparision.
please help me to get the sigle quotes in that query..

Thankyou all for your valuable answers..
  #2 (permalink)  
Old 05-08-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
Hi little_wonder,

Just remove the double quotes it will work fine in normal case ( where the names wont hav single quotes in it)

Code:
 
select no,salary from emp_info where name='$var_name';

Last edited by panyam; 05-08-2009 at 03:47 AM..
  #3 (permalink)  
Old 05-08-2009
little_wonder little_wonder is offline
Registered User
  
 

Join Date: May 2009
Posts: 26
Some Problem with the suggestion.

Hi Panyam,

Thankyou so much for the given solution.

But this i have tried already. but with this i feel a issue that the filed reterived from that query is with spaces and new linr char..

For example when you try to display the result.

#! /bin/sh

var_name=$1

no=`

sqlplus -s user/pwd@DB << EOF

select no,salary from emp_info where name="'$var_name'";

exit

EOF`

echo "No is $no"



The result is like,

no is
123



please give me a solution.
  #4 (permalink)  
Old 05-08-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
Your query is returning name as well as number , but your output shows only number value.

how ever try the following , which is working fine for me.


Code:
#! /bin/sh

var_name=$1

op=`sqlplus -s user/pwd<< EOF

set head off
set feed off
set echo off
set line 999


 
 select no,salary from emp_info where name='$var_name';

exit

EOF`

no=`echo $op |awk '{ print $1}'`
salary=`echo $op |awk '{ print $2}'`
  #5 (permalink)  
Old 05-10-2009
little_wonder little_wonder is offline
Registered User
  
 

Join Date: May 2009
Posts: 26
Thumbs up yah!! its working 5n for me..

Hi Panyam,
Thankyou so much..
Its working fine for me..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0