插入视图时,“ORA-01733:此处不允许使用虚拟列”

时间:2017-11-22 18:38:06

标签: sql oracle10g sql-insert sql-view

我创建了一个名为“view_employee”的视图,如下所示:

CREATE VIEW view_employee AS
SELECT employee.surname || ', ' || employee.name AS comp_name, employee.sex, sections.name AS section_name, employee_age
FROM sections, employee WHERE employee.section = sections.sect_code;

我想使用视图将数据插入到表中,如下所示:

INSERT INTO view_employee VALUES ('Doe, John', 'm', 'Marketing', 34);

以下是表格的列和约束:

create table sections(
  sect_code number(2),
  name varchar2(20),
  income number(5,2)
   constraint CK_sections_income check (income>=0),
  constraint PK_sections primary key (sect_code)
 );

 create table staff(
  ident number(5),
  document char(8),
  sex char(1)
   constraint CK_staff_sex check (sex in ('f','m')),
  surname varchar2(20),
  name varchar2(20),
  address varchar2(30),
  section number(2) not null,
  age number(2)
   constraint CK_staff_age check (age>=0),
  marital_status char(10)
   constraint CK_employee_marital_status check (marital_status in 
('married','divorced','single','widower')),
  joindate date,
   constraint PK_employee primary key (ident),
  constraint FK_employee_section
   foreign key (section)
   references sections(sect_code),
  constraint UQ_staff_document
   unique(document)
);

尝试插入时收到的错误消息如下:

Error starting at Command Line: 1 Column : 1
Error report -
SQL Error: ORA-01733: virtual column not allowed here
01733. 00000 -  "virtual column not allowed here"
*Cause:    
*Action:

如何使用视图将这些值插入表中?提前谢谢。

1 个答案:

答案 0 :(得分:0)

视图不得包含以下任何构造。所以,它可以更新。

       
  • 设置运算符
  •    
  • DISTINCT运算符
  •    
  • 汇总或分析功能
  •    
  • GROUP BY,ORDER BY,MODEL,CONNECT BY或START WITH子句
  •    
  • SELECT列表中的集合表达式
  •    
  • SELECT列表中的子查询
  •    
  • 指定为WITH READ ONLY的子查询
  •    
  • 加入,但有一些例外,如Oracle数据库中所述       管理员指南。