If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > SIngle Quotes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-18-07, 06:35
marksabin marksabin is offline
Registered User
 
Join Date: Aug 2004
Posts: 14
SIngle Quotes

Hi Guys

I am trying to write a script which will concatenate some text (to form a delete command for a separate db) and a field value. My select statement looks like :

Select Concat ('delete * from adifftable where field1 =','''field1''') from myaudittable where myaudittable_date>trunc(sysdate)-1;

This currently returns:

delete * from adifftable where field1 = 'field1'

What I actually want to see is (i.e. I want to return the value of field1)

delete * from adifftable where field1 = '12345';

Can anyone give me any pointers (as I am tearing my hair out!)

Thanks
Reply With Quote
  #2 (permalink)  
Old 01-18-07, 07:08
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
is this oracle? oracle as a CONCAT function?
Code:
select concat('delete * from adifftable where field1 ='
            , ''''
            , field1
            , '''') 
  from myaudittable 
 where myaudittable_date > trunc(sysdate)-1
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-18-07, 07:12
marksabin marksabin is offline
Registered User
 
Join Date: Aug 2004
Posts: 14
Hi

yes using Oracle SQL Plus (8.1.7.0.0). I have tried your suggestion but get:

select concat('delete * from adifftable where field1 ='
*
ERROR at line 1:
ORA-00909: invalid number of arguments
Reply With Quote
  #4 (permalink)  
Old 01-18-07, 08:01
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
well, well, well, invalid number of arguments, eh?

why? because oracle's concat function takes only two arguments!

so try this --
Code:
select concat(
       concat(
       concat('delete * from adifftable where field1 ='
            , '''' )
            , field1 )
            , '''' )
  from ...
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 01-18-07, 08:23
marksabin marksabin is offline
Registered User
 
Join Date: Aug 2004
Posts: 14
Superb - just the job thanks. Virtual pint of beer for you
Reply With Quote
  #6 (permalink)  
Old 01-18-07, 11:33
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Can't Oracle just do
Code:
select 'delete * from adifftable where field1 =''' || field1 || ''''
?
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #7 (permalink)  
Old 01-19-07, 03:31
marksabin marksabin is offline
Registered User
 
Join Date: Aug 2004
Posts: 14
Yes that works too - thanks Peter (maybe I'm inadvertedly trying to overcomplicate things)

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On