使用子查询作为目标插入 [英] Insert using a subquery as a target

查看:87
本文介绍了使用子查询作为目标插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

INSERT INTO (SELECT id,col1,col2,col3,col4 FROM table WHERE col1=1234) 
   VALUES(SEQ.NEXTVAL,2456,'qwew','12312','12312');

对于以上查询,我认为,我只能将行插入到table,其中col1的值为1234.但是,我能够为col1插入1234以外的值.

For the above query, I thought, I can only insert rows to table where the col1 has value of 1234. But, I was able to insert values other than 1234 for col1.

问题:

为什么我们需要上述查询?使用它的现实生活场景是什么?

Why do we need the query like above? What is the real life scenario to use it?

推荐答案

它基本上是允许更新视图的结构.对于多表方案,只能对基础表之一进行INSERT.视图和要插入的表之间必须存在一对一的关系.

It is basically a construct allowing for updateable Views. For a multi table scenario a INSERT can only be to one of the underlying tables. There has to be a One-One relationship between the View and the table being inserted into.

您显示的查询是一个内联视图,扩展了相同的概念.

The query you have shown is a inline view extending the same concept.

在此处阅读更多文档

http://docs.oracle.com/cd/E17952_01/refman-5.1-zh-CN/view-updatability.html

现实生活-能够通过View做到这一点,从而提供了灵活性,便捷性.但是欢迎更多有价值的投入.

Real life - is so as to be able to do this via View gives flexibility, ease. But more valuable inputs are welcome.

这篇关于使用子查询作为目标插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆