列名以数字开头? [英] Column Name beginning with a number?
问题描述
我的一个表中有一个列名:3RD_DIAG_CODE - VARCHAR2 (10 Byte)
I have a column name in one of my tables called: 3RD_DIAG_CODE - VARCHAR2 (10 Byte)
当我尝试运行查询时,它给我突出显示3RD_DIAG_CODE
的以下错误.
When I try to run a query, it gives me the following error highlighting 3RD_DIAG_CODE
.
ORA-00923:在预期位置找不到FROM关键字.
ORA-00923: FROM keyword not found where expected.
如何将这个字段带入而不会在每次将其带入时都引发错误呢?
How can I bring this field in without it throwing an error every time I bring this field in?
推荐答案
如果您使用以数字开头的列名,则需要使用双引号.例如:
If you are using column names that start with a number then you need to use double quotes. For example:
create table foo (
"3RD_DIAG_CODE" varchar2(10 byte) --make sure you use uppercase for variable name
);
insert into foo values ('abc');
insert into foo values ('def');
insert into foo values ('ghi');
insert into foo values ('jkl');
insert into foo values ('mno');
commit;
select * from foo;
3RD_DIAG_C
----------
abc
def
ghi
jkl
mno
select 3RD_DIAG_CODE from foo;
RD_DIAG_CODE
------------
3
3
3
3
3
select "3RD_DIAG_CODE" from foo;
3RD_DIAG_C
----------
abc
def
ghi
jkl
mno
对于错误消息本身,您可能(如BQ所写)在select子句中缺少逗号.
As for the error message itself, you are probably (as BQ wrote) missing a comma from the select clause.
这篇关于列名以数字开头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!