Home » Developer & Programmer » Forms » Updating NOT inserting (form 6i)
icon4.gif  Updating NOT inserting [message #578690] Mon, 04 March 2013 04:06 Go to next message
nada_am
Messages: 9
Registered: January 2013
Location: KSA
Junior Member
Hi

I have a form that used to enter new employees , if the employee ID already registerd then the user can ONLY update the information and NOT adding the same ID with new info.

int the ID item in when-validat-item trigger I put this code
begin

IF :SOURCE_CODE IS NULL THEN MESSAGE('PLEASE ENTER SOURCE CODE');
ELSE
declare --chg#13-3169 nada
l_count NUMBER;
BEGIN
SELECT COUNT (*)
INTO l_count
FROM source_master
WHERE SOURCE_CODE= :SOURCE_CODE;
IF l_count > 0
THEN
msg_alert('This emp is exist and contract end date is ' || :con_end_date);
Set_Item_Property('emp.con_end_date',UPDATE_ALLOWED,PROPERTY_FALSE);
Set_Item_Property('emp..con_start_date',UPDATE_ALLOWED,PROPERTY_FALSE);
Set_Item_Property('emp..source_name',UPDATE_ALLOWED,PROPERTY_FALSE);
Set_Item_Property('emp..contract_type',UPDATE_ALLOWED,PROPERTY_FALSE);
ELSE
null;
END IF;
END;
END IF;
end;

in the save button the code is : commit;

The problem Is : a new record with same ID is inserted every time !! Duplication is happining
please help me
Re: Updating NOT inserting [message #578691 is a reply to message #578690] Mon, 04 March 2013 04:09 Go to previous messageGo to next message
nada_am
Messages: 9
Registered: January 2013
Location: KSA
Junior Member
sorry mistake I meant :
Set_Item_Property('emp.con_end_date',UPDATE_ALLOWED,PROPERTY_true);
Set_Item_Property('emp..con_start_date',UPDATE_ALLOWED,PROPERTY_true);
Set_Item_Property('emp..source_name',UPDATE_ALLOWED,PROPERTY_true);
Set_Item_Property('emp..contract_type',UPDATE_ALLOWED,PROPERTY_true);
Re: Updating NOT inserting [message #578692 is a reply to message #578691] Mon, 04 March 2013 04:10 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Create UNIQUE constraint on employee ID column and let Oracle do the job.
Re: Updating NOT inserting [message #578693 is a reply to message #578692] Mon, 04 March 2013 04:24 Go to previous messageGo to next message
nada_am
Messages: 9
Registered: January 2013
Location: KSA
Junior Member

THX littel foot for replying, but
employee ID is primery key , So it's supposed to be UNIQUE automatically ,, I'm I right?
Re: Updating NOT inserting [message #578695 is a reply to message #578693] Mon, 04 March 2013 04:29 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Yes, you are right. Therefore, even if you try to insert employee with the same ID, Oracle will refuse it.

However: as you said that "a new record with same ID is inserted every time", it seems that what you think is not what you really have (i.e. employee ID is NOT set as a primary key column). Check the table once again.
Re: Updating NOT inserting [message #578696 is a reply to message #578695] Mon, 04 March 2013 04:48 Go to previous messageGo to next message
nada_am
Messages: 9
Registered: January 2013
Location: KSA
Junior Member
thx littel foot,but

the Oracle refueses when user try to insert the same data for the all coulms
ex:
ID NAME DOB
12 lolo 1-jan-1987

if the user enter 12, lolo,1-jan-1987 the oracle refuses to add BUT if user change one data like 12,nada,1-jan-2012 it will be saved as new record !

please any help?
Re: Updating NOT inserting [message #578697 is a reply to message #578696] Mon, 04 March 2013 04:53 Go to previous message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
It means that primary key consists of several columns (i.e. it is a composite key), not only employee ID. (Or, if it is not a primary key, then it might be unique key or index).

What you described is perfectly OK, as far as Oracle is concerned. Now, it depends on you what restriction YOU want to apply. If you want to have unique ID values, then create unique index on ID column. It means that you'll have
- primary key on ID, NAME, DOB
- unique index on ID

Note that the above terminology might differ from the actual situation you have; I don't know what it is because you didn't post CREATE TABLE statement (which would include constraints and indexes as well).
Previous Topic: Check box selection for 2 blocks
Next Topic: About Forms
Goto Forum:
  


Current Time: Fri Apr 26 13:56:14 CDT 2024