Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Daniel.

Asked: July 18, 2016 - 3:57 am UTC

Last updated: July 18, 2016 - 5:06 am UTC

Version: 11.2.0.3

Viewed 1000+ times

You Asked

Hello,Dear Tom:
Document No. repeated in the database!

SELECT T.*,T.ROWID FROM AR_BILL T WHERE T.BILL_NO = '201607-141055001-001-000091'



BILL_ID BILL_TYPE BILL_NO CO_CODE ND REASON PROJECT_CODE APP_ID INPUTOR_ID ORG_CODE INPUT_DATE BILL_STATUS CHECK_MONEY
0A0A031AFFFFFFFFE721849D00000002 EXP_SERVICECHARGE2 201607-141055001-001-000091 141055001 2016 学生劳务费 创新工程—多源数据融合 韩帅 xxzx010 1341372964750 2016-07-14 50 9000.0000
0A0A0474FFFFFFFFE724765800000002 EXP_OUTLAY_OFFICE 201607-141055001-001-000091 141055001 2016 办公室窗帘更换 基本支出 王建军 xxzx006 1341372856312 2016-07-14 20 2485.0000


Developers can not track down the problem!!
Whether it can solve the problem in the database

thanks a lot!!


and Connor said...

Do you have a unique constraint, unique index or primary key constraint on BILL_NO ?

If you don't, then there is nothing stopping duplicates from occurring.

If you do, then check to see if the constraint state is: ENABLE / VALIDATED


A common development error is when people write code like:

Step 1) select count(*) from AR_BILL where BILL_NO = 'X';
Step 2) if result = 0 then insert new row

thinking that this will avoid duplicates. It does *NOT* work in a multi-user environment, because the following can happen:

Session 1:
=========
select count(*) from AR_BILL where BILL_NO = 'X';
> result=0
insert new row

Session 2:
=========
select count(*) from AR_BILL where BILL_NO = 'X';
> result=0
insert new row

Session 1:
=========
commit;

Session 2:
=========
commit;

and just like that ... you have a duplicate.


Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

oracle loyal users

Daniel Liu, July 18, 2016 - 7:01 am UTC

Thanks a lot

It's very useful!!