Home » SQL & PL/SQL » SQL & PL/SQL » generating sequence/primary key based on dept (a column)type
generating sequence/primary key based on dept (a column)type [message #38764] Mon, 13 May 2002 11:06 Go to next message
Amarsey
Messages: 17
Registered: March 2002
Junior Member
Please help me with this problem given to me by my boss.
''I need to create sequence/primary key which will pick the first 4 characters of a column called dept and count the number of records in that same dept to generate the p.k. the sequence must restart at every new dept. eg.
select dept,grade from staffrecord
insert into mytable
values (dept,grade,seq)
Thus the records in mytable should look like
Zoology Senior Clerk ZOOL001
Zoology Junior Clerk ZOOL002
Mathematics Lecturer MATH001
Mathematics T.A MATH002
............ ..... ......
in that order.
Will plsql rather be okay?
Thanks
Re: generating sequence/primary key based on dept (a column)type [message #38767 is a reply to message #38764] Mon, 13 May 2002 12:02 Go to previous message
Rick Cale
Messages: 111
Registered: February 2002
Senior Member
Hi,

I hate to sound cynical but PLEASE send your boss to
data modeling 101. This is absolutely a terrible approach. A sequence is fine but not based on your data. Try providing alternative solutions to your boss
before trying to implement this mess. I know this does not address your question but I really think you
should strive for the proper design it will save everyone in the future.
Previous Topic: Library function no PL/SQL
Next Topic: Execute Immediate
Goto Forum:
  


Current Time: Thu Apr 18 13:04:22 CDT 2024