Please let me know whether Oracle insert statement works if we place the attributes in a different sequence in terms of attribute positions. I am not able to test in dev environment so need expert opinion before I promote changes in PROD directly. Please help.
I am having the following tables:
tableA - col1, col2, col3, col4,col5
tableB - col1, col2, col4, col5
I need to pick the distinct values from tableB and insert into tableA by adding a sequence number to it.
Since distinct and sequence numbers don't work together in insert statements I am using an outer select statement.
Please let me know which of the following 2 options will work ??? If both don't work then please provide your suggestions as well.
option 1 - adding nextval in the outer select statement at the last and keeping col3 as the last position in insert
insert into tableA ( col1, col2, col4, col5, col3 ) select col1, col2, col4, col5, my_seq.nextval as col3 from ( select distinct col1, col2, col4, col5 from tableB );
option 2- adding nextval in the outer select statement in the same sequence and keeping col3 as also in the same position in insert
insert into tableA ( col1, col2, col3, col4, col5 ) select col1, col2, my_seq.nextval as col3, col4, col5 from ( select distinct col1, col2, col4, col5 from tableB );
thanking in advance!!
Both will work. It doesn't matter in which order you insert them, as long as you specify column names (in
insert into
) and match them inselect
that follows.Result:
Why is it OK? Because there are 9 distinct combinations of [
deptno, job
] in Scott'sEMP
table.