Can I escape double quotes in column titles with Oracle?

自闭症网瘾萝莉.ら 提交于 2019-12-11 03:13:54

问题


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           


来源:https://stackoverflow.com/questions/14500872/can-i-escape-double-quotes-in-column-titles-with-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!