有一张表A,里面有两个字段,a,b如果用select * form A是可以查询出来数据的,
但如果select a,b form A 则报列名无效错误!不知哪位大侠可曾遇到这样的错误,求解!拜谢!

解决方案 »

  1.   

    select t.a,t.b form A t 这样试试,会不会自动提示列名。
      

  2.   

    是SELECT * FROM A  是"from",不是 "form"
      

  3.   

    -- 可能是字段名小写啦(楼主先执行我下面的测试代码就明白是怎么回事儿啦):
    scott@TBWORA> create table a("a" varchar2(20), "b" varchar2(20));表已创建。scott@TBWORA> desc a;
     名称                                                              是否为空? 类型
     ----------------------------------------------------------------- -------- --------------------------------------------
     a                                                                          VARCHAR2(20)
     b                                                                          VARCHAR2(20)scott@TBWORA> insert into a("a","b") values('a01','b01');已创建 1 行。scott@TBWORA> select * from a;a                                        b
    ---------------------------------------- ----------------------------------------
    a01                                      b01scott@TBWORA> select a, b from a;
    select a, b from a
              *
    第 1 行出现错误:
    ORA-00904: "B": 标识符无效
    scott@TBWORA> select "a", "b" from a;a                                        b
    ---------------------------------------- ----------------------------------------
    a01                                      b01
      

  4.   

    谢谢你的回复,是这样的,我当时只是图简便才写成:SELECT a,b from a的,实际上我的表名与列名是没有
    重复的,我的数据库版本是10g
      

  5.   

    -- 用下面的查询看一下 A 表的字段名,如果字段名中存在小写,那么你在执行 select 语句引用这些字段名的时候,必须加双引号,例如:
    scott@TBWORA> l
      1  select table_name, column_name, column_id
      2  from user_tab_columns
      3  where table_name='A'
      4* order by column_id
    scott@TBWORA> /TABLE_NAME                     COLUMN_NAME                     COLUMN_ID
    ------------------------------ ------------------------------ ----------
    A                              a                                       1
    A                              b                                       2scott@TBWORA> l
      1  select table_name, column_name, column_id
      2  from user_tab_columns
      3  where table_name='A'
      4* order by column_id
    scott@TBWORA> select a, b from a;
    select a, b from a
              *
    第 1 行出现错误:
    ORA-00904: "B": 标识符无效
    scott@TBWORA> select a, "B" from a;
    select a, "B" from a
              *
    第 1 行出现错误:
    ORA-00904: "B": 标识符无效
    scott@TBWORA> select a, "b" from a;
    select a, "b" from a
           *
    第 1 行出现错误:
    ORA-00904: "A": 标识符无效
    scott@TBWORA> select "a", "b" from a;a                                        b
    ---------------------------------------- ----------------------------------------
    a01                                      b01
      

  6.   

    谢谢你的回复。
    大家说出来 肯定都是交流,你的代码我非常认真地看了,其实我昨天都已经在字段两端加引号了,
    的确不报错,但查询出来的数据都是错的,比如:我的数据是
    a     b
    1     2
    3     4
    但如果我用  select "a","b" 去查询的话,
    出来的结果是:
    a     b
    A     B
    A     B
    您的辛勤回复,我感激不尽!我尊重您的劳动成果,但也请您尊重别人!
      

  7.   


    他在指导你如何去发现问题,你也看到情况了,你创建表的时候,对于字段你使用"",这样会直接把你字段以小写形式保存到数据字典里,你 select a,b 的时候,oracle 会将字段隐式转换为大写然后在数据字典里查找,因为你的列名是以小写形式保存的,所以,会找不到列名,就出错了
      

  8.   

    感谢各位的回复:
    问题解决了,是建表的时候,里面包含了关键字。COLUMN
    谢谢大家的回复!
      

  9.   

    楼主肯定是没有测试
    select "a"写成了 select 'a'
    当然出来就是a了