'oracle insert on subselect gives ORA-00936
I am trying to insert into a table, whose values are same except few from the same table with max sequnce number based on an ID.
insert into ENT_ROLE_USERS_HISTORY(APP_ID,ROLE_ID,TAXID,CREATE_DT,CREATED_BY,STATUS,HIST_ID,ADD_DELETE)
values(
select app_id, role_id, taxid, sysdate, 1233423123, 0, ent_role_us_hist_seq.nextval, 0 from (
select app_id, role_id, taxid from ENT_ROLE_USERS_HISTORY where app_id = 203 and TAXID = 13242342346 order by hist_id desc) where rownum = 1);
I execute the inner select and it works fine and gives me the record but the query fails for the insert. I am getting ORA-00936: missing expression. Can someone let me know whats wrong or is there any other best way to do the same please?
Solution 1:[1]
insert into ENT_ROLE_USERS_HISTORY(APP_ID,ROLE_ID,TAXID,CREATE_DT,CREATED_BY,STATUS,HIST_ID,ADD_DELETE)
select app_id, role_id, taxid, sysdate, 1233423123, 0, ent_role_us_hist_seq.nextval, 0 from
(
select app_id, role_id, taxid from ENT_ROLE_USERS_HISTORY
where app_id = 203 and TAXID = 13242342346 order by hist_id desc
) where rownum = 1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Sergey |