我正在练习实验手册。还有一个问题,我必须在提供的数据的基础上插入数据提供和其他表中的一些数据。
就像问题一样。
Insert data in EMP_TRAINING:
Employee 3400 gets Developer 6i training and his attendance is 87%.
EMP_TRAINING表包含Empno,Tcode和Attendance列。
并且问题是empno和出席是否给出但不是Tcode.Developer 6i是训练表中Tcode的标题。所以我需要写一些查询
insert into EMP_TRAINING values(3400,select Tcode from TRAINING where Title='Developer 6i',87)
但它无法正常工作。我必须做些什么改变?
以及如何使用多个记录(例如
)insert all
into EMP_TRAINING values(3400,select Tcode from TRAINING where Title='Developer 6i',87)
into EMP_TRAINING values(3300,select Tcode from TRAINING where Title='Typing/shorthand',95)
select * from dual;
提交;
解决了
insert all
into EMP_TRAINING values(3400,(select Tcode from TRAINING where Title='Developer 6i'),87)
into EMP_TRAINING values(3300,(select Tcode from TRAINING where Title='Typing/shorthand'),95)
select * from dual;
commit;
答案 0 :(得分:1)
使用values
语句时,您无法使用Insert into...select
关键字。
您必须指定列的顺序,以便将带有select
语句的数据插入EMP_TRAINING
表。
因此,您的查询应如下所示
insert into EMP_TRAINING(Empno, Tcode, Attendance)(select 3400, Tcode, 87 from TRAINING where Title='Developer 6i')