FIN-00100 or FIN-100 AT 100 ROWS.
Main Topics
Browse All TopicsI have several Customers for whom i can develop multiple projects. Each customer has a unique abbreviation ( e.g. FIN, BBL, ...) allways consisting of 3 characters.
Another table "projects" must also have a unique code. For this code, i must create a sequence ( e.g. FIN-001, FIN-002, ..., BBL-001, BBL-002, ...), starting with 001 for each customer.
What is the best way to create this sequence???
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
something like this may work for you.
--add an extra table to store the customer abbreviation.
create table cust_abbrev(
name char(6))
;
insert into cust_abbrev values(
'FIN-00')
;
--add a function to pull the value at runtime.
create or replace function getCustAbbrev
return char is
v_tmp char(6);
begin
select nvl(name,'xxx-')
into v_tmp
from cust_abbrev;
if v_tmp = 'xxx' then
return 'xxx-00';
else
return v_tmp;
end if;
end getCustAbbrev;
/
create sequence SEQ_cust_abbrev
increment by 1
start with 1
nominvalue
nomaxvalue
nocycle;
/
then when you wish to update the pk just use the following.
$master_wa$ORCL@scatcat>se
2 seq_cust_abbrev.nextval
3 from dual;
GETCUSTABBREV||SEQ_CUST_AB
--------------------------
FIN-002
1 row selected.
hi , as ur project codes r complicated like - BBL-001,u can not use a sequence to generate the whole project code,cos charecters like - BBL can not be generated with a sequence.u can use a sequence to generate the number portion of ur project code such as 1 or 2 or 3 etc.then u have to concate two or one "0" before the sequence value to produce a char value which will look like - 001.if ur "next" sequence value goes to two digit then u have to concate one "0" to produce a char value like - 014(of this value the last two charecter "14" will come from the sequence).then u can concate the customer abbreviation "BBL" and the charecter "-" with the generated sequence value(obviously u have to concate the "0" before the sequence value to get ur full project code like BBL-001).so u see u can get only the number value from a sequence which can range from 1 to 100 or more(what ever u wish).and u have to manually concate the customer abbreviation ,the charecter "-" and leading "0" to the "next" sequence value to get the full project code.
u can do this job with a function.here is a point for u that if u want to generate the last three digit of ur project code with a sequence than u have to create one sequence per ur customer.cos, suppose u have a sequence which already generated three values -1,2,3 for a customer -FIN-001,FIN-002,FIN-003.n
BBL-002 because the sequence will not give u the value 1,2 again.so u have to have one sequence for each customer abbreviation or u can use another table to keep values that already generated by the sequence.but all these process will complicate ur job.here i am giving u a function which will not use any sequence but it will give u, ur expected project code.here u have to give the three charecter abbreviation for customer as parameter to the function for which u want to generate code ---
(here i am taking ur project_code column of ur project table as char datatype - u have to have char data type for this column as "BBL-001" is a charecter string.)
create or replace function gen_pro_code(cust_abbv char)
return char
is
max_code number(3);
new_code char(6);
begin
select max(to_number(substr(proje
into max_code
from project
where upper(substr(project_code,
if max_code = 0 then
new_code := upper(cust_abbv) || "-"||"001";
elsif max_code <= 9 then
new_code := upper(cust_abbv)||"-"||"0"
||to_char(max_code);
elsif max_code <= 99 then
new_code := upper(cust_abbv) || "-"||"0"||
to_char(max_code);
else
new_code := upper(cust_abbv) || "-" ||to_char(max_code);
end if;
return new_code;
end ;
SQL > select gen_pro_code('bbl') from dual;
GEN_PRO_CODE('BBL')
----------------------
BBL-001
After u get a value from this function u insert it into the table project.then u again use the function to get a new value for bbl.no matter u use the function for bbl or fin u will get the starting code as BBL-001 and FIN-001.dont forget to make the datatype of ur project_code column as char(6),if u have not already made it like this.
Business Accounts
Answer for Membership
by: drs66Posted on 2003-02-14 at 08:29:32ID: 7950861
what happens when you reach one hundred rows, how do you want the sequence to generate?
daniels@asix.com