INSERT INTO GIADM.GI_TRANSFER_EMP(TRANSFER_EMP_ID,USER_ID,EMP_LAST_NAME,
EMP_FIRST_NAME,EMP_ACTIVE_FLAG)
VALUES (select a.USER_ID as transfer_emp_id,
u.user_id as user_id,
u.user_last_name as emp_last_name,
u.USER_FIRST_NAME as emp_first_name,
u.USER_ACTIVE_FLAG as emp_active_flag
from db_user u, application_group_user a
where u.user_id in
(select a.user_id
from application_group_user a
WHERE a.APP_ID = 46
and a.SEC_GROUP_ID = 17)
and a.user_id = u.user_id);
答案 0 :(得分:4)
语法是
INSERT INTO tablename (columnnames...) VALUES (values...)
或
INSERT INTO tablename (columnnames...)
SELECT values
FROM ...
答案 1 :(得分:2)
当您使用SELECT填充INSERT语句时,不需要VALUES关键字:
INSERT INTO GIADM.GI_TRANSFER_EMP
(TRANSFER_EMP_ID,USER_ID,EMP_LAST_NAME,EMP_FIRST_NAME,EMP_ACTIVE_FLAG)
SELECT a.USER_ID as transfer_emp_id,
u.user_id as user_id,
u.user_last_name as emp_last_name,
u.USER_FIRST_NAME as emp_first_name,
u.USER_ACTIVE_FLAG as emp_active_flag
FROM DB_USER u
JOIN APPLICATION_GROUP_USER a ON a.user_id = u.user_id
AND a.APP_ID = 46
AND a.SEC_GROUP_ID = 17