Column Name beginning with a number?

后端 未结 3 1128
名媛妹妹
名媛妹妹 2020-12-31 17:20

I have a column name in one of my tables called: 3RD_DIAG_CODE - VARCHAR2 (10 Byte)

When I try to run a query, it gives me the following error highlight

3条回答
  •  执笔经年
    2020-12-31 18:12

    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
    

    Edit: As for the error message itself, you are probably (as BQ wrote) missing a comma from the select clause.

提交回复
热议问题