不知道你是怎么插入,是从另一个表中取数据还是直接values(..)
如果从另一个表中取数据,不需要存储过程,insert into tbname a select * from tbname2 b where not exists(select * from tbname2 c where a.字段=c.字段)

解决方案 »

  1.   

    一个笨但是很清晰的思路。
    1、在数据库查找一下有没有你所说的相同或相似的纪录。
    2、如果纪录数为0则表示没有,要添加,这时再Insert也不迟阿;
    3、如果纪录数不为0更好,根本不用insert过程
    感觉速度应该比exist+子查询速度快些.
      

  2.   

    --从另外一张表中取数据楼上语句说了,以下语句是插入一条记录,当col列语句存在“aaaa”时候不插入,不存在则插入表t中:insert into t(col)
    select 'aaaa' from dual 
    where not exists(select col from t where col = 'aaaa')
      

  3.   

    1、在数据库查找一下有没有你所说的相同或相似的纪录
    ---
    这里还是要select的,而且查询出来还要if判断。
    个人感觉还是exists速度快。
      

  4.   

    方法楼上已经说的差不多了,在jsp中调用时,如果用语句,则直接将语句转换为一个string,然后执行,如果是存储过程,则将存储过程名作参数,调用该过程
      

  5.   

    insert into tbname a select * from tbname2 b where not exists(select * from tbname2 c where a.字段=c.字段)
      

  6.   

    1、从另一个表中取数据还是直接values(..)
    如果从另一个表中取数据,不需要存储过程,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')
      

  7.   

    请问
    insert into t(col)
    select 'aaaa' from dual 
    where not exists(select col from t where col = 'aaaa')中的dual指的是什么?
      

  8.   

    to 
    shbjwq430105() 你不要把别人的写的东西综合起来来当作是自己的。
      

  9.   

    insert into t(col)
    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; 
      

  10.   

    关于dual表,你可以查看以下连接就会更加明白:
    http://community.csdn.net/Expert/topic/2694/2694034.xml?temp=.5124323
      

  11.   

    谢谢
    JeromeLiu(烛光)!
    给分