INSERT INTO 插入

多条记录追加查询:(蓝色代码

可以省略value关键字,直接用查询出来的当做value值

insert into table (id ,sex ,age) select id ,'man',age from table2 where name ='B';

单条记录追加查询:

 
insert into table(id ,sex ,age ) valuue(1 ,'man',20)(2,'woman',45);

项目中:

public void updateOrgLevel() {
		String sql1 = "DELETE FROM T_RUT_ORG_LEVEL A WHERE TYPE=0 AND NOT EXISTS " +
				"(SELECT 1 FROM T_RUT_AREA B WHERE A.ID=B.ID AND A.AREA_ORG=B.CENTER AND A.CURRENT_ORG=B.CENTER AND STATUS=11 AND A.PRARENT_ORG IS NOT NULL)";
		String sql2 = "INSERT INTO T_RUT_ORG_LEVEL (ID,AREA_ORG,CURRENT_ORG,PRARENT_ORG,TYPE) " +
				"SELECT A.ID, A.CENTER AREA_ORG, A.CENTER CURRENT_ORG, NULL PRARENT_ORG, 0 TYPE FROM T_RUT_AREA A " +
				"WHERE A.STATUS=11 AND NOT EXISTS (SELECT 1 FROM T_RUT_ORG_LEVEL B WHERE A.ID=B.ID)";NOT EXISTS " +
				"(SELECT 1 FROM T_RUT_AREA B WHERE A.ID=B.ID AND A.AREA_ORG=B.CENTER AND A.CURRENT_ORG=B.CENTER AND STATUS=11 AND A.PRARENT_ORG IS NOT NULL)";
		String sql2 = "INSERT INTO T_RUT_ORG_LEVEL (ID,AREA_ORG,CURRENT_ORG,PRARENT_ORG,TYPE) " +
				"SELECT A.ID, A.CENTER AREA_ORG, A.CENTER CURRENT_ORG, NULL PRARENT_ORG, 0 TYPE FROM T_RUT_AREA A " +
				"WHERE A.STATUS=11 AND NOT EXISTS (SELECT 1 FROM T_RUT_ORG_LEVEL B WHERE A.ID=B.ID)";

 

-----------------------------NOT EXISTS-------------------------

 

 

 

 

你可能感兴趣的:(INSERT INTO 插入)