views:

114

answers:

3

I have a query

select * from table where name in ('52 T&M', '60 T&M');

The "&" is causing the query to expect a parameter. How do I qualify the "&" in the query to sting so that the query can find string with the "&" character in them?

A: 

I assume you use sqlplus, so execute before

set scan off

Michael Pakhantsov
@Michael....the query string is located in the definition of a CURSOR. I tried your suggestion, but suspect the CURSOR definition is messing it up
MikeTWebb
+8  A: 

The ampersand ("&") is a character interpreted by SQLPlus as a variable placeholder. Use:

SET DEFINE OFF
OMG Ponies
@OMG...whereabouts in the Procedure would that code go? As I mention below, the query is in a CURSOR degined before the BEGIN in the procedure
MikeTWebb
@MikeTWebb: At the top of the script. I wager this is an anonymous PLSQL block...
OMG Ponies
+1 I learned something new today! @MikeTWebb It would go as the first line of the script or there abouts. Whether the script is defining a procedure, package body or function via `CREATE OR REPLACE ....` or the script contains an anonymous PL/SQL block.
Shannon Severance
Shannon Severance
+3  A: 

I would normally use set define off as suggested by omg but it is also possible to do it like this:

select *
from table
where name in ('52 T'||Chr(38)||'M', '60 T'||Chr(38)||'M');
Adam Butler