Home > Net >  4 quotes always give different result in SQL Select statement
4 quotes always give different result in SQL Select statement

Time:06-10

So I've been googling for a couple of hours and I still don't understand a single thing about escaping quotes in sql.

Can somebody please explain me if '''' in sql means ' why does select '('||''''||')' give (') why not (''')?

CodePudding user response:

A string in SQL must be enclosed in single quotes, e.g. 'a'

A single quote inside a SQL string is escaped by doubling it: '' - to create a string out of that, you need to enclose that in two single quotes: '''' - so the '' in the middle of that string are the same as the a in my first example.

The expression: '('||''''||')' consists of three string constants:

  1. '(' --> (
  2. '''' --> ' (as explained above)
  3. ')' --> )
  • Related