Advertisement

07.27.2006 at 02:42PM PDT, ID: 21934694
[x]
Attachment Details

Duplicate values on Insert using MAX to create unique field

Asked by jjdahl in Oracle Database

Tags: duplicate, inserts, max, values

We have a project ID column that has the 2 number year followed by an incrementing number.  When we add a new row we need to get the last value and increment it and then concatinate it back together with the year and finally insert it into the database.  The problem is that when 2 users do it at exactly the same time we get a duplicate.  Is there a way to ensure that the number we have is not grabbed by another insert or lock the table for this insert.  We use ADO.NET to run the query using an OdbcCommand and ExecuteNonQuery so there cannot be semicolons in the code or it has to be run as a sepereate query

INSERT INTO GECPLAN (GECPLAN_IS_NUMBER,
TINWSYS_IS_NUMBER, TINWSYS_ST_CODE, ST_PROJECT_ID
 ) VALUES (PLAN_IS_SEQ.NEXTVAL,
1, 1, (SELECT Distinct to_char(SysDate, 'YY') || '-' ||
SUBSTR(('0000' || (SELECT NVL(MAX(SUBSTR(st_project_id, 4, 9))+1, 1) AS ProjNum FROM gecplan
where DECODE(LENGTH(TRIM(TRANSLATE(st_project_id, '+-0123456789', ' '))),null,1,0) = 1
AND st_project_id LIKE to_char(SysDate, 'YY') || '-%')),
LENGTH((SELECT NVL(MAX(SUBSTR(st_project_id, 4, 9))+1, 1) AS ProjNum FROM gecplan
where DECODE(LENGTH(TRIM(TRANSLATE(st_project_id, '+-0123456789', ' '))),null,1,0) = 1
AND st_project_id LIKE to_char(SysDate, 'YY') || '-%')), 5)
FROM GECPLAN ))Start Free Trial
[+][-]07.27.2006 at 02:59PM PDT, ID: 17196950

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Oracle Database
Tags: duplicate, inserts, max, values
Sign Up Now!
Solution Provided By: rbrooker
Participating Experts: 7
Solution Grade: A
 
 
[+][-]07.27.2006 at 03:00PM PDT, ID: 17196957

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.27.2006 at 03:04PM PDT, ID: 17196978

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.27.2006 at 03:13PM PDT, ID: 17197056

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.27.2006 at 11:11PM PDT, ID: 17198655

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.27.2006 at 11:41PM PDT, ID: 17198756

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.28.2006 at 01:34AM PDT, ID: 17199118

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.28.2006 at 05:36AM PDT, ID: 17200534

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.28.2006 at 05:50AM PDT, ID: 17200665

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.28.2006 at 02:17PM PDT, ID: 17204639

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.31.2006 at 05:36AM PDT, ID: 17214989

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.31.2006 at 12:18PM PDT, ID: 17218378

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.31.2006 at 01:55PM PDT, ID: 17219140

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32