如何使视图不只读
我创建了一个只读视图,
create view EMP_VU AS
select ename employee_name, deptno, empno
from emp
with READ ONLY CONSTRAINT EMP_VU_Read_ONLY;
如何使其不只读?
当我尝试将信息插入视图时出现此错误,因此我假设这是我的只读问题。
SQL> insert into EMP_VU (employee_n,deptno, empno)
values (Stutte, 40, 8888);
values (Stutte, 40, 8888)
*
ERROR at line 2:
ORA-00984: column not allowed here
我做了一个更改,这是我得到的新错误,
SQL> insert into EMP_VU (employee_name, deptno, empno)
values ('Stuttle', '40', '8888');
insert into EMP_VU (employee_name, deptno, empno)
*
ERROR at line 1:
ORA-00001: unique constraint (CIS605.EMP_EMPNO_PK) violated
这是视图
SQL> select * from EMP_VU;
EMPLOYEE_N DEPTNO EMPNO
---------- ---------- ----------
KING 10 7839
BLAKE 30 7698
CLARK 10 7782
JONES 20 7566
MARTIN 30 7654
ALLEN 30 7499
TURNER 30 7844
JAMES 30 7900
WARD 30 7521
FORD 20 7902
SMITH 20 7369
EMPLOYEE_N DEPTNO EMPNO
---------- ---------- ----------
SCOTT 20 7788
ADAMS 20 7876
MILLER 10 7934
14 rows selected.
I created a view that I make read only
create view EMP_VU AS
select ename employee_name, deptno, empno
from emp
with READ ONLY CONSTRAINT EMP_VU_Read_ONLY;
How do i make it not read only?
I get this error when I try to insert information into the view so i am assuming thats my problem that is read only.
SQL> insert into EMP_VU (employee_n,deptno, empno)
values (Stutte, 40, 8888);
values (Stutte, 40, 8888)
*
ERROR at line 2:
ORA-00984: column not allowed here
I made a change heres the new error I get
SQL> insert into EMP_VU (employee_name, deptno, empno)
values ('Stuttle', '40', '8888');
insert into EMP_VU (employee_name, deptno, empno)
*
ERROR at line 1:
ORA-00001: unique constraint (CIS605.EMP_EMPNO_PK) violated
Heres the View
SQL> select * from EMP_VU;
EMPLOYEE_N DEPTNO EMPNO
---------- ---------- ----------
KING 10 7839
BLAKE 30 7698
CLARK 10 7782
JONES 20 7566
MARTIN 30 7654
ALLEN 30 7499
TURNER 30 7844
JAMES 30 7900
WARD 30 7521
FORD 20 7902
SMITH 20 7369
EMPLOYEE_N DEPTNO EMPNO
---------- ---------- ----------
SCOTT 20 7788
ADAMS 20 7876
MILLER 10 7934
14 rows selected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的错误消息是违反了主键。您正在使用已存在的主键插入数据。从钥匙的名称来看,它是关于员工编号的。
简而言之,不要插入与任何现有记录具有相同员工编号的记录?
我还注意到,在一个查询中,您的员工姓名字符串周围没有引号。在另一个例子中,您对数值进行了引号。
您需要确定每列的数据类型,并且仅在需要时使用引号。 (字符串和日期,但不是数字)
Your error message is a breach of a primary key. You're inserting data with a primary key that already exists. From the name of the key, it's abotu the employee number.
In short, don't insert records with the same employee number as any existing records?
I've also noticed that in one query you don't have quotes aroudn your string for the employee name. And in another you have quotes around numeric values.
You need to identify the data types for each column, and only use quotes where they're needed. (Strings and Dates, but not numbers)