这种应该创建成包,创建包时,包的定义和包的内容被分别地生成.具体可以看看相关的资料,我给你一个具体例子:
包定义:
create or replace package wfe_flow_dbfunc is
-----------------------------------------------------------------------------------
function inst_create (
i_tmpl_id in wfe_flow_tmpl.tmpl_id%type,
i_user_id in sys_users.id%type,
i_inst_id in wfe_flow_inst.inst_id%type,
i_inst_name in wfe_flow_inst.inst_name%type,
o_form_file out wfe_flow_form.form_file%type,
o_task_id out wfe_flow_task.task_id%type
) return varchar2;
end wfe_flow_dbfunc;包体:
create or replace package body wfe_flow_dbfunc is
function inst_create (
i_tmpl_id in wfe_flow_tmpl.tmpl_id%type,
i_user_id in sys_users.id%type,
i_inst_id in wfe_flow_inst.inst_id%type,
i_inst_name in wfe_flow_inst.inst_name%type,
o_form_file out wfe_flow_form.form_file%type,
o_task_id out wfe_flow_task.task_id%type
) return varchar2 is
v_form_id wfe_flow_form.form_id%type:='';
v_node_id wfe_flow_inst_node.node_id%type:='';
begin
o_task_id:=-1;
o_form_file:='';
if ut_tmpl_ok(i_tmpl_id)<>'1' then return '错误:非法的流程模板id -> '||i_tmpl_id; end if;
if ut_user_ok(i_user_id)<>'1' then return '错误:非法的用户id -> '||i_user_id; end if;
if lengthb(i_inst_id)<>'32' then return '错误:非法的流程实例id -> '||i_inst_id; end if;
if ut_inst_ok(i_inst_id)<>'0' then return '错误:已经存在的流程实例id -> '||i_inst_id; end if; begin
--取模板的form_id,form_name
select ff.form_id,ff.form_file into v_form_id,o_form_file
from wfe_flow_tmpl ft,wfe_flow_form ff
where ft.tmpl_id=i_tmpl_id and ff.form_id=ft.form_id;
--插入流程实例记录
insert into wfe_flow_inst
(inst_id,inst_name,state,tmpl_id,form_id,
create_user,create_time,locker,locktime,des)
values (i_inst_id,i_inst_name,'Y',i_tmpl_id,v_form_id,
i_user_id,sysdate,null,null,null);
--复制所有的模板节点到流程实例节点
insert into wfe_flow_inst_node
( inst_id,node_id,node_pid,node_idx,node_name,node_type,
node_skip,node_target,node_current,node_rights,
node_users,node_users_cp,node_limit
)
(select i_inst_id,t.node_id,t.node_pid,t.node_idx,t.node_name,t.node_type,
t.node_skip,t.node_target,t.node_current,t.node_rights,
t.node_users,t.node_users_cp,t.node_limit
from wfe_flow_tmpl_node t where t.tmpl_id=i_tmpl_id);
exception when others then
return '错误:创建流程实例失败 -> '||sqlerrm;
end; begin
--取实例节点的启动节点
begin
select i.node_id into v_node_id from wfe_flow_inst_node i
where i.inst_id=i_inst_id and i.node_idx=1;
exception when NO_DATA_FOUND then
return '错误:启动流程实例失败,该流程的模板未定义(空流程)';
end;
--取一个任务号
select wfe_flow_seq_task_id.nextval into o_task_id from dual;
--生成并开始一个任务
insert into wfe_flow_task
(task_id,task_pid,inst_id,node_id,user_id,real_user_id,do_begin_time,do_end_time,do_sent_time)
values (o_task_id,0,i_inst_id,v_node_id,i_user_id,i_user_id,sysdate,null,null);
--修改启动节点的属性成实际情况
update wfe_flow_inst_node
set node_type=10,node_skip=0,node_target=1,node_current=1,
node_users=i_user_id,node_users_cp=null,node_limit=-1
where inst_id=i_inst_id and node_idx=1;
exception when others then
return '错误:启动流程实例失败 -> '||sqlerrm;
end;
return '';
end;
end wfe_flow_dbfunc;
包定义:
create or replace package wfe_flow_dbfunc is
-----------------------------------------------------------------------------------
function inst_create (
i_tmpl_id in wfe_flow_tmpl.tmpl_id%type,
i_user_id in sys_users.id%type,
i_inst_id in wfe_flow_inst.inst_id%type,
i_inst_name in wfe_flow_inst.inst_name%type,
o_form_file out wfe_flow_form.form_file%type,
o_task_id out wfe_flow_task.task_id%type
) return varchar2;
end wfe_flow_dbfunc;包体:
create or replace package body wfe_flow_dbfunc is
function inst_create (
i_tmpl_id in wfe_flow_tmpl.tmpl_id%type,
i_user_id in sys_users.id%type,
i_inst_id in wfe_flow_inst.inst_id%type,
i_inst_name in wfe_flow_inst.inst_name%type,
o_form_file out wfe_flow_form.form_file%type,
o_task_id out wfe_flow_task.task_id%type
) return varchar2 is
v_form_id wfe_flow_form.form_id%type:='';
v_node_id wfe_flow_inst_node.node_id%type:='';
begin
o_task_id:=-1;
o_form_file:='';
if ut_tmpl_ok(i_tmpl_id)<>'1' then return '错误:非法的流程模板id -> '||i_tmpl_id; end if;
if ut_user_ok(i_user_id)<>'1' then return '错误:非法的用户id -> '||i_user_id; end if;
if lengthb(i_inst_id)<>'32' then return '错误:非法的流程实例id -> '||i_inst_id; end if;
if ut_inst_ok(i_inst_id)<>'0' then return '错误:已经存在的流程实例id -> '||i_inst_id; end if; begin
--取模板的form_id,form_name
select ff.form_id,ff.form_file into v_form_id,o_form_file
from wfe_flow_tmpl ft,wfe_flow_form ff
where ft.tmpl_id=i_tmpl_id and ff.form_id=ft.form_id;
--插入流程实例记录
insert into wfe_flow_inst
(inst_id,inst_name,state,tmpl_id,form_id,
create_user,create_time,locker,locktime,des)
values (i_inst_id,i_inst_name,'Y',i_tmpl_id,v_form_id,
i_user_id,sysdate,null,null,null);
--复制所有的模板节点到流程实例节点
insert into wfe_flow_inst_node
( inst_id,node_id,node_pid,node_idx,node_name,node_type,
node_skip,node_target,node_current,node_rights,
node_users,node_users_cp,node_limit
)
(select i_inst_id,t.node_id,t.node_pid,t.node_idx,t.node_name,t.node_type,
t.node_skip,t.node_target,t.node_current,t.node_rights,
t.node_users,t.node_users_cp,t.node_limit
from wfe_flow_tmpl_node t where t.tmpl_id=i_tmpl_id);
exception when others then
return '错误:创建流程实例失败 -> '||sqlerrm;
end; begin
--取实例节点的启动节点
begin
select i.node_id into v_node_id from wfe_flow_inst_node i
where i.inst_id=i_inst_id and i.node_idx=1;
exception when NO_DATA_FOUND then
return '错误:启动流程实例失败,该流程的模板未定义(空流程)';
end;
--取一个任务号
select wfe_flow_seq_task_id.nextval into o_task_id from dual;
--生成并开始一个任务
insert into wfe_flow_task
(task_id,task_pid,inst_id,node_id,user_id,real_user_id,do_begin_time,do_end_time,do_sent_time)
values (o_task_id,0,i_inst_id,v_node_id,i_user_id,i_user_id,sysdate,null,null);
--修改启动节点的属性成实际情况
update wfe_flow_inst_node
set node_type=10,node_skip=0,node_target=1,node_current=1,
node_users=i_user_id,node_users_cp=null,node_limit=-1
where inst_id=i_inst_id and node_idx=1;
exception when others then
return '错误:启动流程实例失败 -> '||sqlerrm;
end;
return '';
end;
end wfe_flow_dbfunc;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货