473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to handle "select a,b where c=' 1 & 2' in a 'hard coded' odbc query

57
I am maintaining an asp page that builds a select query as a plain old string and executes it using oracle odbc.

There is basically too much code to change over to stored proccedures or other nice means.

How can I escape a & ? Using sql+ there is an escape on command, is there a similar concept for odbc? Is this an odbc question rather than oracle?
Feb 21 '08 #1
6 2068
debasisdas
8,127 Expert 4TB
can you kindly post the query for my reference.
Feb 21 '08 #2
jhaxo
57
can you kindly post the query for my reference.
sorry i did not get an email notification.
That is really the query.

"select a,b from mytable where c=' 1 & 2' ".
c is a varchar, a and b are columns . I don't have the freedom to do a sp or p, or a parameterized command. And worse still, it has to work with Oracle and Access.

I did discover there is an escape concept in sql+ that you can turn on and then \& is interpreted as a character and not a place holder for a parameter.
Mar 5 '08 #3
amitpatel66
2,367 Expert 2GB
sorry i did not get an email notification.
That is really the query.

"select a,b from mytable where c=' 1 & 2' ".
c is a varchar, a and b are columns . I don't have the freedom to do a sp or p, or a parameterized command. And worse still, it has to work with Oracle and Access.

I did discover there is an escape concept in sql+ that you can turn on and then \& is interpreted as a character and not a place holder for a parameter.
If you change your query to something like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. select a,b from mytable where c IN ('1','2')
  3.  
  4.  
Mar 6 '08 #4
jhaxo
57
If you change your query to something like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. select a,b from mytable where c IN ('1','2')
  3.  
  4.  
no, sorry c is a varchar that has the literal value '1 & 2'.
like 'burger & fries'.
Mar 7 '08 #5
amitpatel66
2,367 Expert 2GB
no, sorry c is a varchar that has the literal value '1 & 2'.
like 'burger & fries'.
Try this way:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> SET SCAN OFF
  3. SQL> declare
  4.   2  c varchar2(20) := '1 & 2 & 3';
  5.   3  v_output VARCHAR2(2);
  6.   4  s_sql VARCHAR2(200);
  7.   5  BEGIN
  8.   6  c:= CHR(39)||REPLACE(c,' & ',',')||CHR(39);
  9.   7  s_sql:= 'SELECT ''x'' FROM DUAL WHERE ''x'' NOT IN ('||c||')';
  10.   8  EXECUTE IMMEDIATE s_sql INTO v_output;
  11.   9  dbms_output.put_line('Format of IN parameter:'||c);
  12.  10  dbms_output.put_line('Output using Formatted IN:'||v_output);
  13.  11  end;
  14.  12  /
  15. Format of IN parameter:'1,2,3'
  16. Output using Formatted IN:x
  17.  
  18. PL/SQL procedure successfully completed.
  19.  
  20. SQL> 
  21.  
  22.  

Remember in the above example the 2 single colons are used in the select statement and not a double quote
Mar 7 '08 #6
amitpatel66
2,367 Expert 2GB
Something like this also will work:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> SET SCAN OFF
  3. SQL> select * from dual where 'x' not in (REPLACE('1 & 2',' & ',','))
  4.   2  /
  5.  
  6. D
  7. -
  8. X
  9.  
  10. SQL> 
  11.  
  12.  
Mar 7 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
16
by: lkrubner | last post by:
Are there any benchmarks on how much an extra, unneeded VARCHAR, CHAR, INT, BIGINT, TEXT or MEDIUMTEXT slows down a database call with MySql? PostGre info would also be useful. I'm trying to...
3
by: Radu | last post by:
Hi. I have lots of processing to do on the server - from the client (Access) I call a sproc which returns a recordset (the sproc is essentially a big "select"). With the obtained data , I need to...
6
by: GSteven | last post by:
(as formerly posted to microsoft.public.access.forms with no result) I've created a continuous form which is based on a straightforward table (ex - customers - 100 records). On the form there is...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as & to be valid. I don't have Firefox my self and don't wont to install it only...
5
by: Henning M | last post by:
Hi all, I having some problems with Access and selecting records between dates.. When I try this in access, it works fine!! "Select * from Bilag Where Mdates Between #1/1/2006# And...
3
by: divya | last post by:
Hi, I have a table tblbwday with 2 fields Name and Birthday.I have written this script for displaying evryday names of the people on that day. <% set objConn...
13
by: Ragnar | last post by:
Hi, 2 issues left with my tidy-work: 1) Tidy transforms a "&amp;" in the source-xml into a "&" in the tidied version. My XML-Importer cannot handle it 2) in a long <title>-string a wrap is...
3
by: =?Utf-8?B?UmljaA==?= | last post by:
I need to build a sql string that looks like this: strSql = "Select * from tbl1 Where x In (123,456,789)" or strSql = "Select * from tbl1 Where x In (123,456,789,527,914)" The numbers...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.