Insert With Select

Description: Basic Insert with Select example with a subquery.

SET feedback off;
SET pagesize 0;
 
CREATE TABLE TEST (a NUMBER, b VARCHAR(10), c VARCHAR(10));
 
INSERT INTO TEST VALUES ( 15, 'abc','def' );
INSERT INTO TEST VALUES (998, 'max','min' );
INSERT INTO TEST VALUES (  7, 'bla','bla' );
INSERT INTO TEST VALUES (632, 'now','then');
 
INSERT INTO TEST
  (a,b,c)
  (SELECT                   AA,
                            BB,
                            CC
  FROM
    (SELECT MAX(a) +1       AA      FROM TEST),
    (SELECT 'new'           BB,
            'old'           CC      FROM dual));
 
SELECT * FROM TEST WHERE a = (SELECT MAX(a) FROM TEST);
 
DROP TABLE TEST;

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.