Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: Inserting into SELECT statement Jump to:  
Category: >> Oracle PL/SQL >> Inserting into SELECT statement Bookmark and Share

<< lastnext >>

Snippet Name: Inserting into SELECT statement

Description: You can use a select-statement within an INSERT statement to insert zero, one, or more rows into a table from the result table of the select-statement.

One use for this kind of INSERT statement is to move data into a table you created for summary data.

Also see:
» TABLE - Using Select Statement With D...
» SQL Insert Example
» SELECT: Case insensitive search
» SELECT: Partition Select
» SELECT: Select For Update
» SELECT: Using Functions
» SELECT: Get DISTINCT / UNIQUE values
» SELECT: Get UNIQUE / DISTINCT values
» SELECT: Scalar Select
» SELECT with HAVING Clause
» SELECT with GROUP BY Clause
» SELECT with WHERE Clause
» SELECT with SAMPLE clause
» SELECT placement
» SELECT into a table
» SELECT name columns
» SELECT
» UPDATE: Update from a SELECT statement
» INSERT With Returning Clause
» Create Table INSERT (CTAS)
» Inserting into SELECT statement
» INSERT WITH CHECK OPTION
» INSERT FIRST WHEN
» INSERT ALL WHEN
» INSERT ALL
» INSERT WHEN
» INSERT: Using A Record
» INSERT with Select
» INSERT: Multiple Column Table Or View ...
» INSERT: Multiple Column Table Or View ...

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 04th, 2009

INSERT INTO (<SELECT Statement>);
 
  INSERT INTO CORPDATA.EMPTIME
     (EMPNUMBER, PROJNUMBER, STARTDATE, ENDDATE)
  SELECT EMPNO, PROJNO, EMSTDATE, EMENDATE
    FROM CORPDATA.EMPPROJACT
 
--Notes:
 
-- 1. The number of columns implicitly or explicitly listed in the INSERT statement must equal the number of columns listed in the select-statement.
-- 2. The data in the columns you are selecting must be compatible with the columns you are inserting into when using the INSERT with select-statement.
-- 3. In the event the select-statement embedded in the INSERT returns no rows, an SQLCODE of 100 is returned to alert you that no rows were inserted. If you successfully insert rows, the SQLERRD(3) field of the SQLCA has an integer representing the number of rows SQL actually inserted. This value is also available from the ROW_COUNT diagnostics item in the GET DIAGNOSTICS statement.
-- 4. If SQL finds an error while running the INSERT statement, SQL stops the operation. If you specify COMMIT (*CHG), COMMIT(*CS), COMMIT (*ALL), or COMMIT(*RR), nothing is inserted into the table and a negative SQLCODE is returned. If you specify COMMIT(*NONE), any rows inserted before the error remain in the table.
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 222 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?