mysql 创建function
drop FUNCTION IF EXISTS WORKNO;
create function WORKNO(projectno VARCHAR(5),workno VARCHAR(10) )
returns VARCHAR(100)
begin
declare seq integer;
declare timestr integer;
declare temp_seq integer;
declare number_return VARCHAR(100);
set timestr = DATE_FORMAT(now(),'%Y');
select sequence+1 INTO temp_seq from pe_number where work_no = workno AND project_no=projectno;
UPDATE pe_number SET sequence = temp_seq WHERE work_no = workno AND project_no=projectno;
IF ROW_COUNT() = 0 THEN
SET seq = 1;
INSERT INTO pe_number(project_no,work_no,timestr,sequence) values(projectno,workno,timestr,seq);
end IF;
select CONCAT(project_no,work_no,timestr,LPAD(sequence,6,0)) INTO number_return from pe_number WHERE work_no = workno AND project_no=projectno;
return number_return;
end;