Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape single quotes in Sybase

Tags:

sql

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
like image 835
Pez Cuckow Avatar asked Sep 21 '12 10:09

Pez Cuckow


People also ask

How do you escape the special characters in Sybase?

Use the escape clause to specify an escape character. Any single character in the server's default character set can be used as an escape character. If you try to use more than one character as an escape character, Adaptive Server generates an exception.

How do you escape a single quote?

Single quotes need to be escaped by backslash in single-quoted strings, and double quotes in double-quoted strings.

How do I skip a single quote in SQL?

The simplest method to escape single quotes in SQL is to use two single quotes. For example, if you wanted to show the value O'Reilly, you would use two quotes in the middle instead of one. The single quote is the escape character in Oracle, SQL Server, MySQL, and PostgreSQL.


1 Answers

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!

like image 53
Pez Cuckow Avatar answered Oct 04 '22 03:10

Pez Cuckow