Adding Multiple Rows to a Table : Insert with subquery « Insert Delete Update « Oracle PL / SQL






Adding Multiple Rows to a Table

   
SQL>
SQL> CREATE TABLE Student (
  2     StudentID INT NOT NULL PRIMARY KEY,
  3     Name      VARCHAR(50) NOT NULL);

Table created.

SQL>
SQL> INSERT INTO Student (StudentID,Name) VALUES (1,'Tom');

1 row created.

SQL> INSERT INTO Student (StudentID,Name) VALUES (2,'Jack');

1 row created.

SQL> INSERT INTO Student (StudentID,Name) VALUES (3,'Mary');

1 row created.

SQL> INSERT INTO Student (StudentID,Name) VALUES (4,'Bill');

1 row created.

SQL> INSERT INTO Student (StudentID,Name) VALUES (5,'Cat');

1 row created.

SQL>
SQL>
SQL> CREATE TABLE Professor (
  2     ProfessorID INT NOT NULL PRIMARY KEY,
  3     Name        VARCHAR(50) NOT NULL);

Table created.

SQL>
SQL>
SQL> INSERT INTO Professor (ProfessorID, Name)
  2     SELECT StudentID + 7, Name
  3     FROM Student;

5 rows created.

SQL>
SQL> drop table Professor;

Table dropped.

SQL> drop table Student;

Table dropped.

   
    
    
  








Related examples in the same category

1.Perform more complicated inserts using sub-selects
2.Merge into a table
3.Insert into ... select
4.Conditional INSERT Statement
5.Insert bulk by insert ... into ... select
6.To insert records into a table using a subquery:
7.Use bulk collect and rownum to insert first 10 records