The DB2 unique sequential number generation recently developed system requires that many unique document numbers be generated. The rule prefix of the document number is _ yyyyMMdd + sequential number, such as P_201210160001 and P_201210160002. Because multiple document numbers are generated. Therefore, a seed table named ID (PK) primary key IDBIGINTNET_ID network IDBIGINTCOMP_ID was created in the system. The seed value of SMALLINTSEED_DATE VARCHAR (16) SEED_VALUE was prefixed with VARCHAR (6) SEED_SPLIT seed separator VARCHAR (2) CREATE_TIME VARCHAR (19) the document number generated by NET_ID, COMP_ID, and SEED_TYPE creates a unique index www.2cto.com. There is a stored PROCEDURE to implement the SQL code drop PROCEDURE PROC_SEQ_SEED_GET select * FROM BAS_SEQ_SEED CREATE PROCEDURE into (IN ne T_id_in bigint, -- network id in comp_id_in bigint, -- join company id in seed_type_in integer, -- serial number type IN seed_date_in VARCHAR (16), -- current date yyyymmdd format OUT return_value VARCHAR (32) -- RETURN Value) P1: begin declare seed_value_t integer; DECLARE distinct varchar (16); DECLARE return_value_t integer DEFAULT 1; DECLARE rs1 cursor with return for select SEED_VALUE, SEED_DATE FROM same as t where t. NET_ID = net_id_in and t. COMP_ID = comp_id_in and t. SEED_TYPE = seed_type_in for update; OPEN rs1; FETCH rs1 into seed_value_t, IF (seed_value_t is null) then -- the table record does, SEED_DATE, SEED_VALUE) VALUES (nextval for SE_EXPRESSBAS, net_id_in, comp_id_in, tables, tables, 1); commit; SET return_value_t = 1; end; else begin -- set tables = tables Mt (current timestamp, 'yyyymmdd'); if (seed_date_in = seed_date_t) then -- begin update every set SEED_VALUE = SEED_VALUE + 1 where NET_ID = net_id_in and COMP_ID = comp_id_in and SEED_TYPE = seed_type_in; SET return_value_t = seed_value_t + 1; end; else -- Non- in update BAS_SEQ_SEED set SEED_DATE = seed_date_in, SEED_VALUE = 1 where NET_ID = net_id_in and COMP_ID = comp_id_in and SEED_TYPE = seed_type_in; SET re Turn_value_t = 1; end if; if (return_value_t <10) then set returnvalue = seed_date_in | '000' | char (return_value_t ); elseif (values> = 10 AND return_value_t <100) then set returnvalue = values | '00' | char (return_value_t); elseif (return_value_t> = 100 AND return_value_t <1000) then set returnvalue = seed_date_in | '0' | char (return_value_t); end if; close rs1; END P1 large data volume Concurrent Test generate process ID only I. Java calls the Stored Procedure www.2cto.com Java code try {Session session = this. getHibernateSession (); String SQL = "{call SCM_WULIU.PROC_SEQ_SEED_GET (?,?,?,?,?)} "; CallableStatement cs = session. connection (). prepareCall (SQL); // The Stored Procedure Calls cs. setLong (1, net_id); cs. setLong (2, comp_id); cs. setShort (3, seed_type); cs. setString (4, PubMethod. getCurSysDate ("yyyyMMdd"); cs. registerOutParameter (5, Types. CHAR); cs.exe cute (); result = cs. getString (5); // get the output parameter session. flush () ;}catch (Exception he) {throw he ;}finally {closeSession ();}