我表中的数据大概如下:学号 姓名 分数
1234 张三 50,
5678 王五 70, 另外我要插入的数据有可能包括表中已经存在的,比如说要插入的数据有(1234,张三,50),(2356,李四,60),(5678,王五,70),(8787,赵七,60);怎么写一个sql语句,使在插入的时候碰到已经存在的就不插入,不存在的就插入?
1234 张三 50,
5678 王五 70, 另外我要插入的数据有可能包括表中已经存在的,比如说要插入的数据有(1234,张三,50),(2356,李四,60),(5678,王五,70),(8787,赵七,60);怎么写一个sql语句,使在插入的时候碰到已经存在的就不插入,不存在的就插入?
解决方案 »
- oracle pl/sql编程中,在java应用程序中给一个type对象类型赋值出错
- Oracle连接查询问题
- 谁能帮我改一下这个函数
- 出现“oracle management server 服务启动后又停止了,一些服务自动停止,如果他们没什么可做的“
- 请教大家一个循环的问题
- 关于dblink的数据库间insert数据的效率问题
- 触发器没有反映,不知道哪里出问题了! :(
- oracle 数据库的小问题
- 怎么从oracle数据库中导出脚本(.sql)?
- 对于含有40万条数据的表进行数据转换——十万火急!!!!
- 急!用union连接后的多表查询的问题?
- 如何把一个长字符串按指定字符并且要在规定的每段最大长度内进行分段
insert into tb1 select * from tb2 b where not exists(select * from tb1 where 学号=b.学号)
2 is
3 cu number;
4 begin
5 select count(1) into cu from test where a=v_a and b=v_b and c=v_c;
6 if cu>0 then
7 raise_application_error(-20003,'数据已存在');
8 else insert into test values(v_a,v_b,v_c);
9 end if;
10 end;
11 /Procedure createdSQL> select * from test; A B C
---------- ---------- ----------
1 as 90
2 afgs 58
3 ggf 87
4 adds 987
1 fddfsg 4
11.25 456 rows selectedSQL> exec p_insert(1,'as',90);begin p_insert(1,'as',90); end;ORA-20003: 数据已存在
ORA-06512: 在 "BWDASOC.P_INSERT", line 7
ORA-06512: 在 line 1SQL> exec p_insert(1,'as',99);PL/SQL procedure successfully completed