How to escape single quotes in Sybase

后端 未结 2 2241
花落未央
花落未央 2021-02-19 05:49

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
<         


        
相关标签:
2条回答
  • 2021-02-19 06:38

    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!

    0 讨论(0)
  • 2021-02-19 06:41

    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
    
    0 讨论(0)
提交回复
热议问题