表 字段 1 字段2 字段3
table1 no type bill
在想table中添加数据时,先判断字段bill,如果有了就不插:select count(*) cou from table where bill='123';if(cou<>0)"";这样避免对bill的重复,但是要是两个人同时插入一样的bill,而且数据库中没有的,一起插,就插了两条,请问有谁能告诉我怎么处理吗?oracle10g数据库。
table1 no type bill
在想table中添加数据时,先判断字段bill,如果有了就不插:select count(*) cou from table where bill='123';if(cou<>0)"";这样避免对bill的重复,但是要是两个人同时插入一样的bill,而且数据库中没有的,一起插,就插了两条,请问有谁能告诉我怎么处理吗?oracle10g数据库。
看来只能循环declare
CURSOR get_Attr_ IS
SELECT *
FROM table_name A ;
temp_ Number;
Begin
FOR rec_ IN get_Attr_ LOOP
Begin
select count(*) Into temp_ from table where bill='123';
If temp_ =0 Then
Insert Into table_name(col)Values(col_value);
End If;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('error:'||Sqlerrm);
END;
END LOOP;
end;
这个的没有则插入,用MERGE函数很合适。
也就是主键约束
alter table table add constraint foreign key (bill) references table (bill);