1

我尝试使用带有减号、点等符号的列名。Oracle SQL 解析器不包括它们。像这样:

select
    a.ID as Article-Number, a.Name as Name
from
    Articles a
where
    (a.ID = '3264')

它不例外a.ID as 'Article-Number'(说"FROM keyword not found where expected")。我可以在列名中有符号吗?

4

4 回答 4

4

您可以使用双引号 ( ") 来转义别名和列名:

select
    a.ID as "Article-Number", a.Name as "Name"
from
    Articles a
where
    (a.ID = '3264')
于 2014-10-29T06:51:38.930 回答
3

我可以在列名中有符号吗?

我在这里使东西自动化,所以我所有的别名都会得到双引号。重要的是我知道如何在我的别名中使用任何字符串。

在 Oracle 中,您使用双引号 ( ") 来转义模式的名称(包括列名)。

但是,如果您尝试使事情自动化,则应注意以下几条规则:

  • 名称必须为 1 到 30 个字符。超出此限制的标识符将引发
    ORA-00972: identifier is too long
  • 名称不能包含引号 ( ") 或\0(aka nul) 字符

有关详细信息,请参阅Oracle 的模式对象命名规则

于 2014-10-29T09:05:18.877 回答
2

问题仅Article-Number作为别名。别名name非常好。

SQL> select e.ename as name from emp e where rownum = 1;

NAME
----------
SMITH

SQL> select e.ename as Article-Number from emp e where rownum = 1;
select e.ename as Article-Number from emp e where rownum = 1
                         *
ERROR at line 1:
ORA-00923: FROM keyword not found where expected


SQL> select e.ename as "Article-Number" from emp e where rownum = 1;

Article-Nu
----------
SMITH

SQL>

因此,只有as alias to escapedouble-quotation才需要标记。Article-Number-

于 2014-10-29T07:02:35.240 回答
0

1.我猜使用括号[]

Select [Name@Symbol], [#Sharp!#Column] from Your table

在此之前,您需要按此名称创建

2.您可以使用同义词来使用2个或多个名称...

如果您在评论中需要这种方式,请说。

东大

于 2019-04-29T06:56:29.300 回答