I am trying to insert some data into a table from a select statement. I know I can do it like this:
insert into new_logs (idLog, logEntry)
(select idLog, logEntry from old_logs)
But, I am running into a problem when trying to execute this type of query when I need to pass in a sequence value:
insert into new_logs (idLog, logEntry)
(select LOGSEQ.NEXTVAL, logEntry from old_logs)
I think the problem is because the sequence comes from the dual table, but the query above implies that it comes from the old_logs table.
I also tried this,
insert into new_logs (idLog, logEntry)
select next_value for LOGSEQ, logEntry from old_logs
But I still can't get it to work. Could someone please tell me if what I am trying to do is possible? All I want to do is run an insert statement using a select query and a sequence on another schema.
logseqis a sequence that is owned by a user other than the one you are running theINSERTstatement as? Does your user have permission to use the sequence? If so, you'd need a fully qualified object name unless you are creating synonyms for the sequence.