Oracle pl-sql escape character (for a “ ' ”)

前端 未结 7 2518
灰色年华
灰色年华 2020-12-14 06:31

When I am trying to execute INSERT statement in oracle, I got SQL Error: ORA-00917: missing comma error because there is a value as Alex\'s T

7条回答
  •  隐瞒了意图╮
    2020-12-14 07:19

    Instead of worrying about every single apostrophe in your statement. You can easily use the q' Notation.

    Example

    SELECT q'(Alex's Tea Factory)' FROM DUAL;
    

    Key Components in this notation are

    • q' which denotes the starting of the notation
    • ( an optional symbol denoting the starting of the statement to be fully escaped.
    • Alex's Tea Factory (Which is the statement itself)
    • )' A closing parenthesis with a apostrophe denoting the end of the notation.

    And such that, you can stuff how many apostrophes in the notation without worrying about each single one of them, they're all going to be handled safely.

    IMPORTANT NOTE

    Since you used ( you must close it with )', and remember it's optional to use any other symbol, for instance, the following code will run exactly as the previous one

    SELECT q'[Alex's Tea Factory]' FROM DUAL;
    

提交回复
热议问题