Automatism Generate Serial number...

--Sql server2000 Environment
--Generate serial number for tbale tb_bh
--Section 1:
--Create a table,Table name:tb_bh

CREATE TABLE tb_bh(BH varchar(20))

--Section 2,Create a procedure as below.
 
IFEXISTS (SELECT name FROM sysobjects
           WHERE name = N'proc_tb_bh'AND type ='P')
   DROPPROCEDURE proc_tb_bh
GO
 
CREATE PROCEDURE proc_tb_bh
AS
insertinto tb_bh SELECTconvert(varchar(8),getdate(),112)+RIGHT(100001+ISNULL(RIGHT(MAX(BH),5),0),5) FROM tb_bh
GO
--Selection 2,Run the Procedure generate serial number

execute proc_tb_bh

select * from tb_bh

--Oracle9i Environment

Section 1

-- Create sequence

create sequence BH

minvalue 1

maxvalue 99999

start with 1

increment by 1

cache 20;

--Section 2

create or replace procedure proc_tb_bh

as

begin

insert into tb_bh values(bh.nextval);

commit;

end proc_tb_bh;

 

posted on 2006-04-15 11:52  封起De日子  阅读(168)  评论(0编辑  收藏  举报

导航