不知道你是怎么插入,是从另一个表中取数据还是直接values(..)
如果从另一个表中取数据,不需要存储过程,insert into tbname a select * from tbname2 b where not exists(select * from tbname2 c where a.字段=c.字段)
如果从另一个表中取数据,不需要存储过程,insert into tbname a select * from tbname2 b where not exists(select * from tbname2 c where a.字段=c.字段)
1、在数据库查找一下有没有你所说的相同或相似的纪录。
2、如果纪录数为0则表示没有,要添加,这时再Insert也不迟阿;
3、如果纪录数不为0更好,根本不用insert过程
感觉速度应该比exist+子查询速度快些.
select 'aaaa' from dual
where not exists(select col from t where col = 'aaaa')
---
这里还是要select的,而且查询出来还要if判断。
个人感觉还是exists速度快。
如果从另一个表中取数据,不需要存储过程,insert into tbname a select * from tbname2 b where not exists(select * from tbname2 c where a.字段=c.字段)2、插入一条记录,当col列语句存在“a”时候不插入,不存在则插入表t中:
insert into t(col)
select 'a' from dual
where not exists(select col from t where col = 'a')
insert into t(col)
select 'aaaa' from dual
where not exists(select col from t where col = 'aaaa')中的dual指的是什么?
shbjwq430105() 你不要把别人的写的东西综合起来来当作是自己的。
select 'aaaa' from dual
where not exists(select col from t where col = 'aaaa')中的dual指的是什么?
--
它是oracle中的一个伪表,它只有一个字段DUMMY,只有一条记录。因为pl/sql不支持:
select 1 + 2;这样的语法。它必须要有from子句,所有为了完整,又为了方便计算与调试,就有了select 1 + 2 from dual;
如果不用dual表,其他的表返回的可能是多条记录,那样就不方便调试与计算了。
如果你知道t-sql,那可以对比一下以下两条语句:
t-sql: select upper('aa')
pl/sql: select upper('aa') from dual;
http://community.csdn.net/Expert/topic/2694/2694034.xml?temp=.5124323
JeromeLiu(烛光)!
给分