select * from table_name where column like '&nbsp' - sql

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.

Have a look at this:
SQL Plus FAQ
e.g.
SET ESCAPE '\'
SELECT '\&abc' FROM dual;

Easier way:
SET DEFINE OFF
See:
SET DEFINE

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

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)

Related

Variable in sql file with single quote

SELECT SWAP_PARTITIONS_BETWEEN_TABLES
(':SCHEMA_NAME.:TABLE_NAME',:PARTITION_KEY,:PARTITION_KEY,
':SCHEMA_NAME.:TABLE_NAME');
This is a vertica query in sql file
:SCHEMA_NAME and :TABLE_NAME in sql file is not getting replaced by the argument passed probably because of single quotes
Try this:
\set source '''src_schema.src_table'''
\set target '''tgt_schema.tgt_table'''
SELECT SWAP_PARTITIONS_BETWEEN_TABLES
(:source,:PARTITION_KEY,:PARTITION_KEY,:target);
If you want to use different variables for SCHEMA and TABLE, you can:
\set schema '''myschema'''
\set table '''mytable'''
And then:
SELECT SWAP_PARTITIONS_BETWEEN_TABLES
(:schema||'.'||:table,:PARTITION_KEY,...);

Apostrophe(') in SQL data,oracle 11g

I need to insert data into a sql table using a csv file with apostrophe(') and ('') in few rows.
I was able to handle it using the below method.
Get open_quote and close_quote and put the username and email_id between these two variable.
SELECT CHR(113)||CHR(39)||CHR(91) INTO OPEN_QUOTE FROM dual;
SELECT CHR(93)||CHR(39) INTO CLOSE_QUOTE FROM dual;
enter image description here
It looks ugly.I could have used replace but i opted for this method.
Could you please let me know of any other method so that my code looks good?
Attached is the screenshot of the dynamic sql.
You can have a single quote in a string by doubling it. For instance:
select 'It''s Bob''s book'
from dual;
As of Oracle 10g in PL/SQL you can have:
V_SQL_STATEMENT := q'[It's Bob's book]';
See Oracle SQL Reference for details on text literals.
Use the alternative-quoting mechanism and several REPLACEs instead of concatenation. It's a little extra work but it makes it clearer what the final SQL statement will look like.
v_sql_statement := replace(replace(replace(replace(
q'[
insert into login
(USER_ID,CLIENT_ID,EMAIL,PSWD_HASH,NETWORK_ID,FAILED_LOGIN_ATTEMPTS,NAME)
VALUES
(
LOGIN_SEQ.nextval,
#P_CLIENT_ID#,
'#PARSE_EMAIL#',
#V_PSWD_HASH#,
NULL,
0,
'#USER_NAME#'
)
]'
, '#P_CLIENT_ID#', p_client_id)
, '#PARSE_EMAIL#', parse_email(lower(c1.email)))
, '#V_PSWD_HASH#', v_pswd_hash)
, '#USER_NAME#', nvl(c1.name, generate_user_name(parse_email(c1.email))))
;

Inserting T-SQL query text into SQL Server table

Can anyone help me to get this work.
[HOD_DESC] LIKE '%r%' is a formatted T-SQL query and I want insert into a table.
EXEC sp_s_saveReportSearch 'x= r ', '[HOD_DESC] LIKE '%r%''
Just escape the quotes by doubling them:
EXEC sp_s_saveReportSearch 'x= r ','[HOD_DESC] LIKE ''%r%'''
I really hope there's a good reason why you're doing this, however.
Double the quotes around quoted part of your SQL string:
EXEC sp_s_saveReportSearch 'x= r ','[HOD_DESC] LIKE ''%r%'''
In the column, inserted value will be [HOD_DESC] LIKE '%r%'

How to escape single quotes in Sybase

I come from MySQL and the below query doesn't work in Sybase. How should I escape single quotes?
UPDATE Animals SET NAME = 'Dog\'s friends' WHERE uid = 12
If working with Sybase, having got used to MySQL which more database users have experience you may soon discover you are unable to escape single quotes with backslash in.
So how do you escape quotes in Sybase? In fact, in Sybase SQL the single quote acts as the escape character.
See below for an example UPDATE statement in both “languages”:
MySQL
UPDATE Animals SET NAME = 'Dog\'s friends' WHERE uid = 12
Sybase
UPDATE Animals SET NAME = 'Dog''s friends' WHERE uid = 12
I’m not entirely sure this makes sense to me (especially as it looks like a double quote) but there you go!
You can create a custom function to escape quotes :
CREATE FUNCTION "ESCAPE_QUOTES"(in a_string long varchar)
returns long varchar
begin
return replace(a_string, '''', '''''');
end

Query Help - String in where clause has & character

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.
SET DEFINE OFF;
Will work to turn the prompting for variable off..
or
SET ESCAPE ON;
SELECT 'blah \& blah' AS DES FROM DUAL;
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.
You can escape the ampersand character by using concatenation, like this:
select * from table
where table_id in ('265' || '&' || '310', '266' || '&' || '320')