• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Escaping Sequence problem.

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Last time I really stuck with a simple String initilization problem..
I have initilise a String variable with a large sql query as follow.....

String query="select rpad('WS'||substr(h.wdcode,1,7),15) wdcode,
rpad('S'||substr(d.brandcode,1,4)||decode(b.unitsperpack,5000,5,7000,1,10000,2,12000,3,6000,4,0),15) brandcode,
rpad(to_char(h.secsaledate,'"WEEK1M"MMYYYY'),15)docdt,
rpad('CL12',15) trntype,lpad(to_char(sum(d.retailer),'999999999'),15) qty
from basis.dp_secsaleheader h, basis.dp_secsaldetail d, basis.brandmstr b
where h.secsaleheadercode = d.secsaleheadercode and d.secsalecategorycode=1 and b.company='GPI' and d.brandcode = b.brandcode and to_number(to_char(h.secsaledate,'DD')) <=7 and h.secsaledate >= to_date'01092006','DDMMYYYY') and h.secsaledate <= to_date('30092006','DDMMYYYY')and d.retailer>0 and substr(h.wdcode,1,2) ='02' group by rpad('WS'||subst(h.wdcode,1,7),15),rpad('S'||substr(d.brandcode,1,4)||decode (b.unitsperpack,5000,5,7000,1,10000,2,12000,3,6000,4,0),15),
rpad(to_char(h.secsaledate,'"WEEK1M"MMYYYY'),15),
rpad('CL12',15)"
This gives me a error String literal is not properly closed by double quote.
Can any one guide me how to initilise this query to a String variable.
Thanks
harish.
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this all on one line, or are those line breaks really in your code? You have to have it all on one line in the code. I also can't tell if you have actual double quotes inside the String or not; if you do, then you need to put a "\" backslash before each one.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I were you I'd build the statement using a StringBuffer/StringBuilder. It will make it a lot easier to maintain.
e.g.


As Ernest said, there's probably some double quotes in there which you will need to escape.

[ October 04, 2006: Message edited by: Joanne Neal ]
[ October 04, 2006: Message edited by: Joanne Neal ]
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And I would put linebreaks and tabs into the sql, to make debugging more convenient:

How readable is that?
[ October 04, 2006: Message edited by: Stefan Wagner ]
 
Harish Chandra Durgapal
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest,Joanne,Stefan

Thanks a lot .It solved my problem.
 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic