Mega Code Archive

 
Categories / Oracle PLSQL Tutorial / Insert Update Delete
 

Insert into select with where clause

SQL> SQL> CREATE TABLE employee (   2  id          number,   3  name        varchar(100),   4  birth_date  date,   5  gender      varchar2(30) ); Table created. SQL> SQL> INSERT INTO employee (id,name,birth_date,gender ) SELECT 300,'H',NULL,'MALE' from   dual d   2  where not exists (SELECT 1 FROM   employee x WHERE  x.id = '300' ); 1 row created. SQL> SQL> select * from employee;     ID ------ NAME ---------------------------------------------------------------------- BIRTH_DATE GENDER ---------- ------------------------------    300 H null       MALE 1 row selected. SQL> SQL> drop table employee; Table dropped.