4

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?

3 Answers 3

6

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

3
  • @Davit khaburdzania your question was whats the meaning of using select * from dual in the end of the insert statment not what is select * from dual is ?! i think my answer is suitable to your question ! right?
    – shareef
    Commented Jun 3, 2012 at 8:40
  • yes my question was what is the meaning of using select * from dual. and if syntax of using insert all is so i get it. but why should i always select something after inserting something? Commented Jun 3, 2012 at 8:52
  • because the syntax of using it is requiring selecting something and if you dont want to select somthing you have to select * from dual and it will return one empty row its just how it is!
    – shareef
    Commented Jun 3, 2012 at 9:02
4

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

This is now possible, without any tricks, using Database 23c.

create table if not exists NEW_OLD_DEMO (
   ID       number
      generated by default as identity ( start with 1 cache 20 )
   , NAME   varchar2(50)
   , SALARY number
);

alter table NEW_OLD_DEMO add constraint NEW_OLD_DEMO_PK primary key ( ID )
   using index;
    
insert into NEW_OLD_DEMO (NAME, SALARY)
values ('Smitty', 10),
        ('Kristopher', 20 ),
        ('Larry', 30);

And querying the data back out -

enter image description here

Docs:

Not that you're limited to passing 65535 entries via the VALUES clause. Also, this will be done as a single transaction.

And this wouldn't be a good answer for Oracle w/o a reference to the oracle-base example for using this feature, across insert, merge, with, and select.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.