Can I escape double quotes in column titles with O

2019-07-14 03:04发布

问题:

Creating a table with a double quote to escape the real double quote doesn't seem to work in Oracle's SQL syntax:

CREATE TABLE "MyTable" (
"Col""umn 1" varchar(168)
);

The above fails. Is there any way to escape the double quote to make 'Col"umn 1'?

回答1:

You can not. According to the documentation:

Nonquoted identifiers can contain only alphanumeric characters from your database character set and the underscore (_), dollar sign ($), and pound sign (#). Database links can also contain periods (.) and "at" signs (@). Oracle strongly discourages you from using $ and # in nonquoted identifiers.

Quoted identifiers can contain any characters and punctuations marks as well as spaces. However, neither quoted nor nonquoted identifiers can contain double quotation marks or the null character (\0).



回答2:

You could, of course, use unicode!

SELECT
    1 "“Unicode Rocks”",
    2 "ʺSooo cooolʺ",
    3 ""My co-workers love me""
FROM DUAL


回答3:

Maybe this will help... But please DO NOT create tables with such columns:

CREATE TABLE DropMe AS
SELECT rpad('X', 168, ' ') "Col''umn1" FROM dual
/

SELECT * FROM DropMe
/

SQL>

Col"umn1
-------------------------------------.....
X