Oracle插入不同位置的属性
请告诉我如果我们按照不同的属性位置顺序放置属性,Oracle insert 语句是否有效。我无法在开发环境中进行测试,因此在直接推动 PROD 中的更改之前需要专家意见。请帮忙。
我有以下表格:
tableA - col1, col2, col3, col4,col5
tableB - col1, col2, col4, col5
我需要从 tableB 中选择不同的值并通过向其添加序列号来插入到表A中。
由于不同和序列号在插入语句中不能一起工作,因此我使用外部选择语句。
请让我知道以下 2 个选项中哪一个有效???如果两者都不起作用,那么也请提供您的建议。
选项 1 - 在最后的外部 select 语句中添加 nextval 并将 col3 保留为 insert 中的最后一个位置
insert into tableA ( col1, col2, col4, col5, col3 ) select col1, col2 , col4, col5, my_seq.nextval as col3 from ( select different col1, col2, col4, col5 from tableB );
选项2-在外部添加nextval选择语句以相同的顺序,并将 col3 保持在插入中的相同位置
insert into tableA ( col1, col2, col3, col4, col5 ) select col1, col2, my_seq.nextval as col3, col4 , col5 from (从 tableB 中选择不同的 col1, col2, col4, col5 );
提前致谢!!
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!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两者都会起作用。只要指定列名称(在
insert into
中)并在后面的select
中匹配它们,插入它们的顺序并不重要。结果:
为什么没问题?因为 Scott 的
EMP
表中有 9 种不同的 [deptno, job
] 组合。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.