multiple row insert in Oracle SQL

元气小坏坏 提交于 2020-01-24 05:49:13

问题


I use multiple row insert syntax in oracle SQL like this:

INSERT ALL
  INTO student(ID, FIRST_NAME, LAST_NAME, AGE)  VALUES(4,'test_name','test_lname',17)
  INTO student(ID, FIRST_NAME, LAST_NAME, AGE)  VALUES(5,'test_name2','test_lname2',20)
  INTO student(ID, FIRST_NAME, LAST_NAME, AGE)  VALUES(6,'test_name3','test_lname3',21)
  select * from dual;

can anyone explain me what is the meaning of using

select * from dual

at the and of statement?


回答1:


it the syntax for INSERT ALL

INSERT ALL
INTO <table_name> VALUES <column_name_list)
INTO <table_name> VALUES <column_name_list)
...
<SELECT Statement>;

if there is nothing you want to select after inserting you do select * from dual

otherwise you do your select you want usually to confirm the insert success

reference




回答2:


The DUAL table is a special one-row table present by default in all Oracle database installations. It is suitable for use in selecting a pseudocolumn such as SYSDATE or USER. The table has a single VARCHAR2(1) column called DUMMY that has a value of 'X'.

More about this here and here.




回答3:


The insert all can be used to insert data from a select statement, to another table In your example you have already provided the values to insert, that's why you need to do the select * from dual, to trigger the insertion.

http://jzab.blogspot.com/2013/05/oracle-insert-multiple-rows-with-single.html



来源:https://stackoverflow.com/questions/10868874/multiple-row-insert-in-oracle-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!