8

I need to find records containing html code such as '&nbsp' But when I try to run the select * from table_name where column like '&nbsp%' I got prompt asking for the value of nbsp. I guess the database thinks that nbsp is a parameter. I am wondering if the is an escape character so that I can tell the database that "&" is part of my query string. I tryed '\&nbsp' but didn't work.

My environment is Oracle 9i with sqlplus client.

Thanks.

Wei Ma
  • 3,125
  • 6
  • 44
  • 72

4 Answers4

11

Have a look at this:

SQL Plus FAQ

e.g.

SET ESCAPE '\'
SELECT '\&abc' FROM dual;
davek
  • 22,499
  • 9
  • 75
  • 95
11

Easier way:

SET DEFINE OFF

See: SET DEFINE

wadesworld
  • 13,535
  • 14
  • 60
  • 93
  • This works very well too. But I saw another answer first, so I had to mark the other one as answer. But one up vote for you :) – Wei Ma Dec 25 '09 at 02:20
2

The backslash should work, but I think you need to start your query with

SET ESCAPE ON
Paddyslacker
  • 1,880
  • 1
  • 14
  • 20
  • Duplicate answer to the other one, but saw it was only 5 mins different from the one that's been upvoted more, and this one was actually first. That's rough voting... here's my +1 – vapcguy Jul 22 '16 at 17:13
0

In PL/SQL, you would use:

BEGIN select <Column> from <Table_name> into <Variable> where <Column> LIKE '\&nbsp\%' ESCAPE '\'; END /

Resources:

Wilcards in SQL on PSOUG.org

LIKE Condition in Oracle® Database SQL Language Reference 11g Release 2 (11.2)

philippeko
  • 501
  • 5
  • 16