从视图插入表时,无效的列ORA- 00904错误

时间:2019-07-03 07:49:52

标签: oracle plsql view

在我的主表中,表结构列没有双引号,但是在View列中有双引号。将视图中的数据插入表中时出错。 这是 tbl

的表结构
create table tbl (ID number(10),
                  name varchar2(50),
                  addr varchar2(200));

视图为-

 create or replace view t_view as
 select "ID", "name", "addr"  from tbl;

t_view -

将数据插入 tbl
insert into tbl
select * from t_view;

然后出现错误ORA- 00904: "addr": Invalid identifier

那么如何解决此问题,我可以从视图创建中删除双引号。

3 个答案:

答案 0 :(得分:3)

删除代码中所有地方的所有双引号。

如果在创建对象时使用它们,则必须始终使用它们,并指定完全相同的字母大小写。

要摆脱这些麻烦,Oracle默认情况下是不区分大小写的,并且会将所有名称都视为大写(但是您可以根据需要以任何方式引用它们,只是不要使用双引号!)。

答案 1 :(得分:0)

Oracle默认将任何对象的名称存储在大写中。如果提供了双引号,那么只有Oracle会按原样存储对象的名称。

  • 双引号-区分大小写
  • 无引号-不区分大小写-将名称存储为大写

在您的情况下,在编写表的DDL时,您没有在双引号中提供列名,因此您的表名和列名存储在元数据的大写中。

您可以使用以下查询看到相同的内容

select table_name, column_name from user_tab_columns where table_name = 'TBL';

要给出答案,请使用以下语法之一创建视图:

create or replace view t_view as
 select ID, name, addr  from tbl; -- no double quotes

create or replace view t_view as
 select "ID", "NAME", "ADDR"  from tbl; -- UPPERCASE column names in double quotes

请参阅演示here

干杯!

答案 2 :(得分:0)

您要完成什么。您的要求没有任何意义。您的预期声明

insert into tbl select * from t_view;

完成与

完全相同的操作
insert into tbl select * from tbl;

这不是您不能(可以)这样做,但只会导致大量重复数据问题或(希望)唯一违反约束。

相关问题