Prevent Duplicate Insertion of Record
I am trying to acheive some thing like this but i beleive
Insert Statement is not allowed in Case or Select is expecting some
thing in return that is why it keeps on giving me Missing
Expression . Is there any other way to prevent duplicate insertion
. i know we can do it by running another Query and then based on
recoundcount or count of that seperate query inserting records but
that i dont want to do .
SELECT CASE
WHEN ( SELECT COUNT(*) FROM THACARA WHERE ORG_CNY_CD = 'US'
AND ORG_REG_NR = '02' AND ORG_DIS_NR = '51') > 0
THEN (' DUPLICATE EXSIST')
ELSE (INSERT INTO THACARA ( USR_NR, ORG_FAC_LOC_NR, )
values ( 'Yousaf', 'FLIMI'))
END AS TEST FROM DUAL;
any ideas ??
It would be a lot better for everyone if you actually put a
unique constraint on your table rather than all this programming
(remember Oracle can have constraints). and preferably handle it in
a proper procedure and not injection - note that the "Answer" in
this thread does not actually return any information about whether
the record was inserted or not, just the actual record (nor does it
update the non-duplicate columns).
BEGIN
insert stuff
return 'inserted'
when DUP_VAL_ON_INDEX
update other stuff not making up the unique columns
return 'duplicate'
END
Similar Messages
-
In my trivial example below I have a Nationality entity. The entity just has the code and Name attributes, with the code being an automatically generated Integer.
Im inserting one record and then trying to prevent the same record being inserted, by setting the ImportType to 1:
truncate table [stg].[Nationality_1_Leaf]
insert into [stg].[Nationality_1_Leaf](importType, ImportStatus_id, BatchTag, Name)
values(1, 0, 'some batch' , 'American' )
select * From [stg].[Nationality_1_Leaf]
exec stg.udp_Nationality_1_Leaf 'VERSION_1', 1, 'some batch'
After this I truncate the staging table and repeat the process. Unfortunately a new record is entered into the Entity even though the name is identical to a record that already exists.
Can anyone explain what im doing wrong here?In MDS only the Code attribute has to be unique. You can create a business rule to enforce uniqueness of other attributes, but business rules will not prevent data loading.
If you use the Name for Code, then this will just work.
Alternatively you can look at the subscription view for your target entity to for any entities that match by name, and either not load that row, or get the Code value so you can perform an update.
David
David http://blogs.msdn.com/b/dbrowne/
when you say "you can look at the subscription view for your target entity to for any entities that match by name, and either not load that row", does this mean that in SSIS I would do a lookup against the subscription view and act accordingly
if the row already exists? -
Preventing duplicate rows insertion
suppose i have a table with 2 columns
no constraints are there
then how i will prevent duplicate rows insertion using triggers.but i tried to solve the poster's requirement.yes, but the trigger does not solve it.
The example you posted above, try this:
do the first insert in your first sql*plus session, and then without committing, open another sql*plus session and do the second insert.
Do you see an error?
SQL> create table is_dup(x number, y varchar2(10));
Table created.
SQL> CREATE OR REPLACE TRIGGER chk
2 BEFORE INSERT ON is_dup
3 FOR EACH ROW
4 BEGIN
5 FOR i IN (SELECT * FROM is_dup)
6 LOOP
7 IF (:NEW.x = i.x) AND
8 (:NEW.y = i.y)
9 THEN
10 raise_application_error(-20005, 'Record already exist...');
11 END IF;
12 END LOOP;
13 END;
14 /
Trigger created.
SQL> insert into is_dup values(123,'MYNAME');
1 row created.
SQL>
SQL> $sqlplus /
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Apr 23 10:17:07 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> insert into is_dup values(123,'MYNAME');
1 row created.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> select * from is_dup ;
X Y
123 MYNAME
123 MYNAME
SQL> commit ;
Commit complete.
SQL> select * from is_dup ;
X Y
123 MYNAME
123 MYNAME
SQL> -
How to prevent duplicate records
Hello all,
This is just a general query. How do we prevent duplicate records at data target level(ODS/InfoCube).
Thanks
S NHi,
for ODS you can either specify in settings option "unique records" (only first combination of keys is saved, second one throws error message) or you can define "overwrite" for update rules to ODS (last occurrence of record is saved).
For InfoCubes I think there isn't such setting and there is no possibility of overwriting existing records. So you have to load first to an ODS object to ensure unique records and update from ODS to InfoCube.
Best regards,
Björn -
How to prevent duplicate entry in Details block
Dear All
I am using Forms 10g.
I have a detail block.
There is a column called Ip_Address.
There i want to prevent duplicate entry .
How can i do this ?hey i have a requirement that to restrict duplicate entry in both block(both multi record).the blocks are DEPT(MATER)
EMP(DETAIL)
the associated fieds in master block DEPT.DEPT_NO,in detail EMP.EMP_ID .
I have done' Kevin D Clarke’s calculated item ' both in master and detail block
its working fine for master block but in case of detail block its only respond to the current session(i.e. if the new value is inserted or save it will restrict another record to be inserted of that last record's value),it does not restrict duplicate value enter ,checking with other existing records(which are saved in earlier session,though after query it is shown on the form)
can anyone guide me why its not working -
Hi there,
I wonder if there is any approach to prevent duplicate login to Weblogic
server using the same userID and password.(weblogic provided or programmatic
is OK). I tried to use a table to maintain the current active user
information, but when the user just quits the browser or the weblogic server
is shut down, this will not work because the flag still remain in the table.
Does anyone have try it before or know how to do it?
Thanks in advanced.
KenThanks for your reply.
Actually, I am now using the similar solution except that I place a static
field(a hashtable) in the class that implements the
HttpSessionBindingListener to record the current users rather than store the
information in database table. Thus when the application server shuts down,
I don't need to clear the dirty data in the table.
Ken
Andy <[email protected]> wrote in message
news:[email protected]...
>
i'm doing the same thing with an application. i've extended theAuthFilter class
and whenever a user logs into the application i insert a row into a"current users"
table. i also set an object into the user's session that implements theHttpSessionBindingListener.
when the session expires (either by the user by logging out or times outwithin
weblogic) the server calls my class that was inserted into the user'ssession
at which time i remove the row from the "current users" table.
hope this helps -
"Neil Smithline" <[email protected]> wrote:
I believe that due to the loose coupling of a web browser and the server
as
defined in the HTTP spec, there is no way to ensure that both sides have
an
identical concept of "logged in". Any solution you propose will have
errors
as you described below. The server just plain can't tell the difference
between a slow-to-respond user, a user who's browser has crashed, a user
who
is having network problems, etc... This is not a WLS specific problem,
it
is HTTP.
Neil Smithline
WLS Security Architect
BEA Systems
"Ken Hu" <[email protected]> wrote in message
news:[email protected]...
Hi there,
I wonder if there is any approach to prevent duplicate login to
Weblogic
server using the same userID and password.(weblogic provided orprogrammatic
is OK). I tried to use a table to maintain the current active user
information, but when the user just quits the browser or the weblogicserver
is shut down, this will not work because the flag still remain in thetable.
Does anyone have try it before or know how to do it?
Thanks in advanced.
Ken -
Inserting a record in an internal table - Urgent
Hi Friends,
I have a requirement where in I have 2 internal tables say itab1 and itab2.Itab1 has 10 records and itab2 has one record initially.
Now I have to move the records of itab1 into itab2.
My question is if some conditions satisfy,then I need to append the records of itab1 after the single record in itab2.In some other cases I need to insert the records of itab1 before
the single record in itab2.
What is the syntax to attach the records before the record as append statement always attaches the record after the existing record.
Your help is highly appreciated.
Regards,
Vishnu.You can use insert itab index idx .
Alternative 2
... itab INDEX idx
Effect
This variant can only be used for standard tables and sorted tables. Each line line_spec to be inserted into the line before the table index idx and the table index of the following lines is increased by one. A data object of the type i is expected for idx.
If idx contains a value equal to the number of the existing table lines plus one, the new line is appended as the last line in the internal table. If idx contains a greater value, no line is inserted and sy-subrc is set to 4.
An exception that cannot be handled is raised when:
idx contains a value less than or equal to 0
A line to be inserted would cause a duplicate entry in tables with a unique table key
A line to be inserted would disrupt the sort order of sorted tables
Within a LOOP loop, you can omit the addition INDEX. Each line to be inserted is inserted before the current table line of the LOOP loop. However, if the current line is deleted in the same loop pass, the response is undefined.
read help on this .
reward if helpful -
Easiest way to identify/delete/prevent duplicate documents
I don't suppose that the text column (e.g. CLOB) is something that I can use the usual trick to delete duplicates with, is it? I would think rather than compare the actual text column, I'd need to calculate a checksum or something for each document and then delete rows with duplicate checksums. Or is there a better way? I'm trying to prevent, for example, a news article getting inserted 10 times because it's a UPI story that was carried by 10 different sites.
Thanks.Your idea of a checksum is a good one. But I'd compute the checksum, and make it a unique constraint, which would PREVENT duplicates from being inserted. It's usually better to prevent them than to clean them up later.
Tom Best -
Insert/Update Record - Server Behavior
Help Please!
I have several pages with forms that insert records, but I
over the weekend when I went to open them from the web to
insert/update records errors appeared. They were working fine
before. Using PHP, MYSQL and Dreamweaver CS3
I have tried everything I know to do. I have recreated the
page, same problem as well as delete behaviors and reapply them.
Once the server behavior is added it no longer says Insert
Record in the Application window instead it says "Dynamic
Attribute" Further, when I click it to make any changes etc,
instead of the screen for Insert or Update record coming up it is a
"Dynamic Text box" regarding POST or GET or URL stuff.
Edited to add: And once posted, the page only shows an error
and references this line
<html xmlns="
http://www.w3.org/1999/xhtml">
Error Message
Parse error: syntax error, unexpected '<' on line 40
What can I do?You don't say which server-side language you're using, but the way that I would troubleshoot this in PHP is to use echo to display the value of $_SESSION['MM_Username'] at the bottom of the admin page. This is the session variable Dreamweaver uses to control access to a page with username and password. If the value is displayed, it means sessions are working, and the variable hasn't been destroyed.
If that works, move onto the next page, and use echo to display the value of $_SESSION['MM_Username'] as soon as the session has been started. To prevent being redirected to the fail page, temporarily comment out the following line:
header("Location: ". $MM_restrictGoTo);
Basically, you need to check what's happening to the session variable that controls access to the pages. -
How to insert past record after updating the master table in history table through store PROC
Master Table
Party Status
A Active
B Inactive
C Active
D Inactive
Duplicate Table
Party Status
A Active
B Active
C Active
D Inactive
Updated Master Table
Party Status
A Active
B Active
C Active
D Inactive
Party History Table
B Inactive
I have two table one master and another duplicate I need to update master table based on duplicate table insert the record which updated into Party history table as shown above. need help to write store proc.Check MERGE syntax in BOL (example D). There should be a sample with output, e.g.
insert into PartyHistory (Party, [Status])
select Party, [Status] FROM
(MERGE Master M using Duplicate D on M.[Party]=D.[Party]AND M.[Status]<>D.[Status]
WHEN MATCHED THEN UPDATE
SET [Status] = D.[Status]
OUTPUT Deleted.[Party], Deleted.[Status], $Action) AS Changes (Party, [Status], Action) WHERE Action = 'UPDATE'
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
Inserting a record with Functions
I want to insert one record in to table C, the data is coming from two tables ie. table A & B. In this i am summing one field on key fields F1 and F2, and i am inserting some fields from table B. If I am doing this Using a select statement and one inline query for the sum, then it is giving error unique constraint violated. I am joining the 2 tables with the key fields only.
If any one know the solution plz. respond. Thanks in advance.then it is giving error unique constraint violatedThe key that is being violated is the primary key or some unique key on table C. So obviously the result set you are generating from A and B is failing to produce a unique key (maybe because it is producing duplicate rows).
Look at you data structures. Look at your query and its result set. Determine what is wong.
Cheers, APC -
Meeting trouble when inserting a record into dababase using JDBC.
Hi, everyone!
If I want to insert a record in a table of a database, but I
do not know whether there is already a primary key existing in
the database (I mean the value of the record which I want to insert
conflicting, i.e. duplicating, with one of the value of primary
key in the database). So, I have two solutions:
1. check whether there is already a primary key which confilcting
with the value I want to insert, if not, insert into database.
2. do not do any check before and insert the record directly, and catch
SQLException.
But they both have shortcomings. Solution 1 will lost time (must checking first)
and solution 2 will throw a SQLException, and from the Exception, I do not know
how can I infer it is a primary key conflicting exception.
(I do not know how to distinguish it from other type of SQLException, for example,
database name error exception or SQL statement syntax error).
I do not know whether I have made myself understood.
Who have better solutions?
Thanks in advance,
GeorgeIf I use solution 2, can I get some information from
SQLException? For example, can the exception tell me
whether it is a duplicated primary key error or SQL
statememt syntax error? You don't have to look at the error text. You should
look at the error code. But keep in mind that
it is vendor specific. A duplicate key error in Oracle
has different error code then in SQL Server.Sounds good in theory, in practice it leaves a lot to be desired. First one still has to figure out which codes are problematic, and there is still no guarantee that they won't change. Moreover you might find that the code is used for different types of errors, and that won't work.
>
May you can have a look at the sqlstate, this should
be the same across different DB's as it is defined int
he SQL92 standard, but I wouldn't bet on it...
I would bet - against it. -
How to Insert a record in a database table in debugging mode in production
Hi,
How to Insert a record in a database table in debugging mode in production ?
Waiting for kind response.
Best Regards,
Padhy
Moderator Message : Duplicate post locked.
Moderator message : Warning. Don't create multiple threads for same question.
Edited by: Vinod Kumar on May 12, 2011 11:02 AM
Edited by: Vinod Kumar on May 12, 2011 11:04 AMHi Senthil,
Regards,
Phani Raj Kallur
Message was edited by: Phani Raj Kallur -
Preventing duplicate form submission when page is loaded from history
Hi
We have record insertion forms some of which insert unique
records into sql databases and some which may not. Is there a way
of stopping the user pulling the page from history (or using the
back button) and then resubmitting the data?
I have put a trigger on the databases that basically updates
existing data rather than re-inserting it if a duplicate is entered
but as some of the record submissions are not unique this isn't
always possible. I would also rather restrict the submission client
side to reduce bandwidth and database calls.
I have tried various 'no caching' techniques on the page but
none seem to work. Anyone have any bright ideas ... I am all out of
ideas bright or not!!!
TIA
KarenKaren
I have used session variables to control this sort of thing.
Basically the
insert/update statement tests for the existance of a variable
with a
particular name. If no variable exists then this will
indicate that the
request is coming from a history file, and it will not allow
the process.
Equally as part of the insert process change the value in the
variable and
do not allow and insert if the variable holds that value.
Paul Whitham
Certified Dreamweaver MX2004 Professional
Adobe Community Expert - Dreamweaver
Valleybiz Internet Design
www.valleybiz.net
"big_old_bird" <[email protected]> wrote in
message
news:e2totv$ec9$[email protected]..
> Hi
>
> We have record insertion forms some of which insert
unique records into
> sql
> databases and some which may not. Is there a way of
stopping the user
> pulling
> the page from history (or using the back button) and
then resubmitting the
> data?
>
> I have put a trigger on the databases that basically
updates existing data
> rather than re-inserting it if a duplicate is entered
but as some of the
> record
> submissions are not unique this isn't always possible. I
would also
> rather
> restrict the submission client side to reduce bandwidth
and database
> calls.
>
> I have tried various 'no caching' techniques on the page
but none seem to
> work. Anyone have any bright ideas ... I am all out of
ideas bright or
> not!!!
>
> TIA
> Karen
> -
Create a trigger for to prevent duplicate
Hi
How can I to build a trigger for insert , to prevent duplicate register when I use SQLLOADER ?The user guide is your friend.
As for an unique index:
CREATE UNIQUE INDEX <name> ON <table>(<column1>, <column2>);Again, refer to the user guide.
C.
Maybe you are looking for
-
I Removed itunes from my pc, and tried to redownload/install it, now i can't even get it installed, it says " The feature you are trying to use is on a network resource that is unavailable" What do i do to get itunes back on my pc?
-
My Iphone 6 (8.1.2) is very slow and sluggish to response whenever it is connected any bluetooth devices ex. my car audio or bluetooth headsets The moment I disconnect the bluetooth , the phone turns normal again. This happens when i awaken the phone
-
Max RAM MacBook Pro 5.5 13 Inch 2.26 GHz??
What is the maximum RAM that I can install in a MacBook Pro 5.5 13 inch 2.26 GHz processor? I currently have 4 Gigs and I'm hoping to install 8 gig. Also if I can install 8 does anyone have a suggestion as to what RAM to purchase? Thanks in advance
-
IDT High Definition Audio CODEC (No Sound)
i have the same issue but with a HP Elitebook 2540p running Windows 7 64bit. any advice? I tried to install the same driver you suggested above but it doesn't work thanks
-
PProHeadless.exe encountered a problem and must close
PProHeadless.exe a rencontré un problème et doit fermé. ça se passe lorsque j'exporte un fichier pour le convertir en .avi. Le problème est qu'ensuite le chargement ne se fait pas. comment puis-je le résoudre ? PProHeadless.exe encountered a problem