<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Binary Replace / Byte Replace in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847593#M4878436</link>
    <description>&lt;P&gt;I hadn't realised I was that persuasive! LOCATE would be great too. Many thanks.&lt;/P&gt;</description>
    <pubDate>Tue, 09 Dec 2014 13:42:39 GMT</pubDate>
    <dc:creator>justin_willey</dc:creator>
    <dc:date>2014-12-09T13:42:39Z</dc:date>
    <item>
      <title>Binary Replace / Byte Replace</title>
      <link>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaq-p/13847591</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Introduction&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;At the recent excellent Technical Summit held in Waterloo, I was challenged to make the case for a BinaryReplace() built-in function. &lt;/P&gt;
&lt;P&gt;This would be a function that replaced a character string with another character string without reference to collation semantics etc (unlike the existing Replace() function - see &lt;A href="http://sqlanywhere-forum.sap.com/questions/22067/how-do-builtin-string-functions-work-with-binary-data" target="_blank"&gt;this question&lt;/A&gt; for details of how Replace() interprets data. ByteReplace() might be a better name or it could perhaps be implemented as an extension to Replace().&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;What is is the problem?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Imagine you have a database containing data imported from another system, which uses a different character set or is from a different locale. You find that a particular character is incorrectly represented - a frequent example in the UK is the Pound Sterling sign - £. This often appears as ú. No problem you think - write a little routine that runs through all the affected tables and columns doing something like &lt;/P&gt;&lt;PRE&gt;update person set notes=replace(notes,'ú','£')&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;This is q£ite fast, b£t oh dear, yo£ soon find yo£ have q£ite a problem on yo£r hands. ALL yo£r £s (letter after t) have been changed to £s.&lt;/P&gt;
&lt;P&gt;So what you (I've rolled back) have to do is write a letter by letter comparison user defined function (not very elegant example below) which now takes hours and hours to run. The same issue arises with trying to replace capital letters with lower case or vice versa (assuming a case insensitive database) and any operation involving accented characters that are treated alike by a collation.&lt;/P&gt;
&lt;P&gt;There may be a very obvious solution I'm missing - possibly involving casting everything to binary beforehand (which can work for making case sensitive comparisons) - but it has so far evaded me. When I have had to deal with very large scale problems it's been faster to dump the data out, use a grep tool and read it all in again.   &lt;/P&gt;
&lt;PRE&gt;create function BinaryReplace(in x long varchar,in targetascii smallint,
in replacementascii smallint) returns long varchar deterministic begin
  declare rv long varchar;
  declare l integer;
  declare i integer;
  declare c char(1);
  set l=length(x);
  set i=0;
  set rv='';
  while i &amp;lt; l loop
    set i=i+1;
    set c=substr(x,i,1);
    if ascii(c) = targetascii then
      set c=char(replacementascii)
    end if;
    set rv=rv+c
  end loop;
  return rv
end;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Dec 2014 13:30:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaq-p/13847591</guid>
      <dc:creator>justin_willey</dc:creator>
      <dc:date>2014-12-09T13:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Replace / Byte Replace</title>
      <link>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847592#M4878435</link>
      <description>&lt;P&gt;Your request was noted at the summit and added into our set of enhancement requests. I can't make promises but it would be nice if it made it into Zermatt. I also noticed that there is no binary version of LOCATE either.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Dec 2014 13:40:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847592#M4878435</guid>
      <dc:creator>johnsmirnios</dc:creator>
      <dc:date>2014-12-09T13:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Replace / Byte Replace</title>
      <link>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847593#M4878436</link>
      <description>&lt;P&gt;I hadn't realised I was that persuasive! LOCATE would be great too. Many thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Dec 2014 13:42:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847593#M4878436</guid>
      <dc:creator>justin_willey</dc:creator>
      <dc:date>2014-12-09T13:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Replace / Byte Replace</title>
      <link>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847594#M4878437</link>
      <description>&lt;P&gt;Did you think the conference was for you to learn cool things about SQLAnywhere? It's real purpose is so that we can find out what you need. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Dec 2014 13:44:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847594#M4878437</guid>
      <dc:creator>johnsmirnios</dc:creator>
      <dc:date>2014-12-09T13:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Replace / Byte Replace</title>
      <link>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847595#M4878438</link>
      <description>&lt;P&gt;v17? Zermatt? Guys, what are you talking about? Where can us poor non-participants learn about those cool things?&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;OK, for Zermatt, I just have to make it a some hundred miles southward:)&lt;/P&gt;</description>
      <pubDate>Tue, 09 Dec 2014 15:24:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847595#M4878438</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2014-12-09T15:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Replace / Byte Replace</title>
      <link>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847596#M4878439</link>
      <description>&lt;P&gt;I'm quite sure the enhancement request will already take this into account:&lt;/P&gt;
&lt;P&gt;In contrast to Justin's sample, the replacement should not work on a single character/byte but should work - like REPLACE() - with a "search-string" and a "replace-string", allowing both strings to have different length.&lt;/P&gt;
&lt;P&gt;E.g. with German locale, it's often necessary to replace umlauts with their "extended" form (and vice versa, though that's more difficult as it's not a bijective function...), say like&lt;/P&gt;
&lt;PRE class="codehilite"&gt;&lt;CODE&gt;select byte_replace('Müller', 'ü', 'ue');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Dec 2014 04:43:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847596#M4878439</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2014-12-10T04:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Replace / Byte Replace</title>
      <link>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847597#M4878440</link>
      <description>&lt;P&gt;Just another thought:&lt;/P&gt;
&lt;P&gt;For replacing (in contrast to finding), I think it is usually helpful to distinguish case and/or accent, even in a case-insensitive database. In the sample above, I would certainly not want to replace upper-case letters with lower-case and vice versa, even with character semantics. So instead of a separate "binary replace", it might be more comfortable to enhance REPLACE() with a "collation-name/collation-tailoring-option", just like &lt;A href="http://dcx.sap.com/index.html#sa160/en/dbreference/compare-function.html"&gt;COMPARE()&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Dec 2014 14:08:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847597#M4878440</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2014-12-10T14:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Replace / Byte Replace</title>
      <link>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847598#M4878441</link>
      <description>&lt;P&gt;Zermatt aka v17 documentation is now available here: &lt;A href="http://dcx.sap.com/index.html#sqla170/en/html/822e707dc8624445a615b7180321d900.html"&gt;http://dcx.sap.com/index.html#sqla170/en/html/822e707dc8624445a615b7180321d900.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2015 08:46:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847598#M4878441</guid>
      <dc:creator>MarkCulp</dc:creator>
      <dc:date>2015-07-22T08:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Replace / Byte Replace</title>
      <link>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847599#M4878442</link>
      <description>&lt;P&gt;...and the according changes/enhancements can be found here (under the "Improved support for BYTE strings" section):&lt;/P&gt;
&lt;P&gt;&lt;A href="http://dcx.sap.com/index.html#sqla170/en/html/81589a7d6ce21014a977d8e741f4a095.html"&gt;Changes to SQL statements, functions, procedures, and data types&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2015 10:02:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/binary-replace-byte-replace/qaa-p/13847599#M4878442</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2015-07-22T10:02:41Z</dc:date>
    </item>
  </channel>
</rss>

