Query Help - String in where clause has & character
Asked Answered
S

3

5

I am running an SQL (Oracle) statement like that

select * from table 
where table_id in ('265&310', '266&320')

While running through TOAD, it consider & as some variable placeholder and it asks for its value. If it was for 1-2 place holders then I could have set it in TOAD but the in clause has like 200 of strings.

How to put this query?

I want to export the DATASET as SQL INSERT statement, so I can't use this in SQL-PLUS.

Sirenasirenic answered 16/2, 2011 at 18:45 Comment(0)
K
5

In TOAD, you can disable the prompt for substitution variables from the options dialog:

You need to uncheck: View –> Toad Options –> Execute/Compile –> Prompt for Substitution variables.

Kinata answered 16/2, 2011 at 19:15 Comment(0)
F
7
SET DEFINE OFF;

Will work to turn the prompting for variable off..

or

SET ESCAPE ON;
SELECT 'blah \& blah' AS DES FROM DUAL;
Fistula answered 16/2, 2011 at 18:50 Comment(2)
is there any optino to set define off or set define ~ in TOAD?Sirenasirenic
That works when running as a script, but TOAD uses it's own parser for running individual statments. Fortunately, you can disable substitution from the Options menu, as I showed in my answer.Kinata
K
5

In TOAD, you can disable the prompt for substitution variables from the options dialog:

You need to uncheck: View –> Toad Options –> Execute/Compile –> Prompt for Substitution variables.

Kinata answered 16/2, 2011 at 19:15 Comment(0)
H
3

You can escape the ampersand character by using concatenation, like this:

select * from table 
where table_id in ('265' || '&' || '310', '266' || '&' || '320')
Heptangular answered 16/2, 2011 at 18:51 Comment(2)
this is gona be lots of effort :(Sirenasirenic
Another option is to do as Randy suggested and, for example, to set the DEFINE character to something else or off altogether. SET DEFINE ~;Heptangular

© 2022 - 2024 — McMap. All rights reserved.