Home » Developer & Programmer » Forms » Alpha Numeric Sequence Updating Problem. (Oracle 6i forms, windows Xp (Database 10g))
Alpha Numeric Sequence Updating Problem. [message #554889] Fri, 18 May 2012 06:59 Go to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
I have a Typical Issue;
we have document serial Nos increment program,

which has the below query for selecting and Updating, which generates a
Numeric Value;

Select Query:

Select doc_slno
from fin_jv_slno_mas
where jv_month = '05' and
jv_year = '2012'

Output of this Query: 800001

Update Query:

update fin_jv_slno_mas set doc_slno=docno+1 where
jv_year = '2012' and
jv_month = '05'

Output after Updation: 800002.

The above query is a normal Sequence updating for a Numeric Value;
now we need to update it as Alpha Numeric as below

Example: 8A0001

How can we give the above update statement for Alpha Numeric updation?

Thanks in Advance,
Stalin.

[EDITED by LF: removed superfluous empty lines]

[Updated on: Fri, 18 May 2012 14:43] by Moderator

Report message to a moderator

Re: Alpha Numeric Sequence Updating Problem. [message #554890 is a reply to message #554889] Fri, 18 May 2012 07:17 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
You would have to split the value into two parts: 8A and 0001
Then add 1 to the 2nd part and recombine.

Personally I'd store the two parts in seperate columns and only combine them for display.
Re: Alpha Numeric Sequence Updating Problem. [message #554911 is a reply to message #554890] Fri, 18 May 2012 15:32 Go to previous messageGo to next message
Rayam69
Messages: 43
Registered: May 2012
Member
You can also split the A, combine the numeric to 80001 and then get the sequence. When you get the maximum, replace the A with B and restart the sequence from the beginning.
Re: Alpha Numeric Sequence Updating Problem. [message #554915 is a reply to message #554911] Sat, 19 May 2012 03:55 Go to previous messageGo to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
Hi brayampettai,

we cannot replace A to B when getting Maximum.

Actually the sequence will go like;


8A0001
8A0002
8A0003
8A0004
8A0005
8A0006, etc.,

This is the below coding i tried to update as per Cookiemonster;

update fin_jv_slno_mas set doc_slno= SUBSTR(doc_slno,1,2) || ltrim(TO_CHAR(TO_NUMBER(SUBSTR(doc_slno,3,4)+1),'0000') ) 
where jv_year = '2012' 
and   jv_month = '05'


but the above coding works(updating) when we give it in a SQL Developer or any other Front End tool, but when we put the above update statement in a forms 'Procedure_Body' its not working, so the thing i find out is, this update statement works in a Sql Developer not in a Forms Builder, what might be the Cause?

Please reply,

Stalin.



Re: Alpha Numeric Sequence Updating Problem. [message #554916 is a reply to message #554915] Sat, 19 May 2012 05:06 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
It'd help if you how us how it's not working - wrong result, error message?
Re: Alpha Numeric Sequence Updating Problem. [message #554932 is a reply to message #554916] Sat, 19 May 2012 11:29 Go to previous messageGo to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
It shows a Unique Constraint Error.

Actually this table "fin_jv_slno_mas" sequence no. should be changed or incremented.

eg: 8A0001 + 1(as per update statement)

but its not incremented!!!


Re: Alpha Numeric Sequence Updating Problem. [message #554938 is a reply to message #554932] Sat, 19 May 2012 14:01 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
how are you calling it in the form?
Re: Alpha Numeric Sequence Updating Problem. [message #555009 is a reply to message #554938] Sun, 20 May 2012 23:13 Go to previous messageGo to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
Its Called in a Pre-Insert Trigger of the Database Block as
a Procedure Name Called; "JV_Generate"

the coding for the above Procedure is attached with this;

Pls see and reply me...

Re: Alpha Numeric Sequence Updating Problem. [message #555040 is a reply to message #555009] Mon, 21 May 2012 02:15 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Code you posted didn't raise unique constraint violation error because its multiple WHEN OTHERS exception handlers successfully hide whatever happens within that code and all you know is that there was some kind of an error. Maybe you should avoid WHEN OTHERS and catch errors you expect, but let Oracle raise everything else.

Re: Alpha Numeric Sequence Updating Problem. [message #555041 is a reply to message #555009] Mon, 21 May 2012 02:16 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
what table is the block based on?
Re: Alpha Numeric Sequence Updating Problem. [message #555043 is a reply to message #555041] Mon, 21 May 2012 02:19 Go to previous messageGo to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
JDCLine
Re: Alpha Numeric Sequence Updating Problem. [message #555059 is a reply to message #555043] Mon, 21 May 2012 02:52 Go to previous messageGo to next message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
Why are you inserting into the table the block is based on?
It's almost certainly that that's causing the error, not the update.
Re: Alpha Numeric Sequence Updating Problem. [message #555555 is a reply to message #555059] Fri, 25 May 2012 01:36 Go to previous messageGo to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
Yes you are right i should not update with the base table block.

well just now i wrote another select query for sequence update;

select MAX(CAST(SUBSTR(Doc_slno,3,4) AS INT)) + 1 doc_slno
FROM fin_jv_slno_mas WHERE jv_year = '2012' and jv_month = '05'


the output iam getting is:

DOC_SLNO
---------
512

but in this output i need the output as;

DOC_SLNO
---------
0512

how to do this in the above query?

pls reply...

Re: Alpha Numeric Sequence Updating Problem. [message #555558 is a reply to message #555555] Fri, 25 May 2012 01:45 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Your query returns a NUMBER. The result you want is a CHARACTER. Solution depends on the requirement - is it always 4 characters long? Does it always begin with a zero (so you'd just concatenate '0' to the rest), or should the result be LEFT PADDED with zeros (so you'd use LPAD function)?

By the way, "MAX + 1" option is usually not a good choice in a multi-user environment because two (or more) users might do the same thing at the same time and both of them might calculate DOC_SLNO = 512. That might cause DUP-VAL-ON-INDEX error. Sequences (as Oracle objects) are (usually) a better choice.
Re: Alpha Numeric Sequence Updating Problem. [message #555569 is a reply to message #555558] Fri, 25 May 2012 02:42 Go to previous messageGo to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
yeah i used to_char for number conversion and ltrim function to cut the left spaces and added 0.

well its a 6 character long i concate 2 + 4(total 6 character).

Instead of MAX function how can we use?




Re: Alpha Numeric Sequence Updating Problem. [message #555579 is a reply to message #555569] Fri, 25 May 2012 03:54 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I told you at the end of my previous message - a sequence.
Re: Alpha Numeric Sequence Updating Problem. [message #555583 is a reply to message #555579] Fri, 25 May 2012 04:25 Go to previous message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
ok sir let me try it for the sequence.
Previous Topic: problem with GET_ITEM_PROPERTY
Next Topic: how to solve 100500 non-oracle exception?
Goto Forum:
  


Current Time: Fri Jul 05 22:32:23 CDT 2024