Home

December 16th, 2006

SQL Trouble - String Concatenation

  • Dec. 16th, 2006 at 11:02 PM
EvilPHish evil fish shlomi fish

For a web application I'm working on, I need to concatenate many fields delimited by a delimiter into one large text field. So I lookuped up a way to do concatenation in SQL, and found out that there is no standard way to concatenate in SQL:

  1. In MySQL, one uses the a concat() function which accepts multiple arguments.
  2. In Oracle, concat() accepts only two arguments, and there's also the "||" infix operator which can be chained.
  3. In MS SQL Server, one uses the "+" operator.
  4. In SQLite also has the "||" operator.
  5. PostgreSQL also has the || operator

In short, there's no portable way to do such an elementary operation. The "||" operator seems to be the most widely supported but it is not supported by MSSQL and MySQL. Thus, for the application I wrote I ended up doing the concatenation in Perl.

('ANSI ' || 'SQL' || ' Standard')-- (Assuming it will work in your SQL implementation).

Latest Month

August 2008
S M T W T F S
     12
3456789
10111213141516
17181920212223
24252627282930
31      

Tags