create or replace procedure text(
startTime in varchar2, [color=red] in标记为输入参数[/color]endTime in varchar2,
timeType in number,
spID in number,
newBlackCount out number , [color=red] out标记为输入参数[/color]
blackTotalCount out number,
mdn in varchar2
)
is
strsql varchar2(5000); [color=red] 定义变量[/color]
basicstrsql varchar2(5000);
strsql_1 varchar(5000);
strsql_2 varchar(5000);
strsql_3 varchar(5000);
v_dataCount number;
pattern varchar(10) ;
begin
--初始化参数
strsql_1 :='';
strsql_2 :='';
strsql_3 :='';
newBlackCount := 0 ;
blackTotalCount := 0 ;
if timeType = 0 then
pattern :='yyyy-mm-dd' ;[color=red]定义时间样式[/color]
else
pattern :='yyyy_mm';
end if ;
--开始时间结束时间内新增黑名单数
basicstrsql := 'select count(black.object) blackcount from nm_black_and_object black where 1=1 ' ;
if spID > 0 then
basicstrsql := basicstrsql || ' and black.sp_id ='||spID ;
end if ;
strsql := basicstrsql ;
if startTime is not null then
strsql_1 := ' and to_char(create_date,'''||pattern||''') >=''' ||startTime|| '''' ;
strsql := strsql || strsql_1 ;
end if ;
if endTime is not null then
strsql_2 := ' and to_char(create_date,'''||pattern||''') <=''' ||endTime|| '''' ;
strsql := strsql || strsql_2 ;
end if ;
if spID >0 then
strsql_3 := ' and black.sp_id = '||spID||'' ;
strsql := strsql || strsql_3 ;
end if ;
execute immediate strsql into v_dataCount;
newBlackCount := newBlackCount + v_dataCount ;
strsql := basicstrsql || strsql_2||strsql_3;
execute immediate strsql into v_dataCount;
blackTotalCount := blackTotalCount + v_dataCount ;
end text;
一个小例子 这是我第一次写存储过程,有很多的不足 ,希望高手能多多评点 ,java小生不胜感激
startTime in varchar2, [color=red] in标记为输入参数[/color]endTime in varchar2,
timeType in number,
spID in number,
newBlackCount out number , [color=red] out标记为输入参数[/color]
blackTotalCount out number,
mdn in varchar2
)
is
strsql varchar2(5000); [color=red] 定义变量[/color]
basicstrsql varchar2(5000);
strsql_1 varchar(5000);
strsql_2 varchar(5000);
strsql_3 varchar(5000);
v_dataCount number;
pattern varchar(10) ;
begin
--初始化参数
strsql_1 :='';
strsql_2 :='';
strsql_3 :='';
newBlackCount := 0 ;
blackTotalCount := 0 ;
if timeType = 0 then
pattern :='yyyy-mm-dd' ;[color=red]定义时间样式[/color]
else
pattern :='yyyy_mm';
end if ;
--开始时间结束时间内新增黑名单数
basicstrsql := 'select count(black.object) blackcount from nm_black_and_object black where 1=1 ' ;
if spID > 0 then
basicstrsql := basicstrsql || ' and black.sp_id ='||spID ;
end if ;
strsql := basicstrsql ;
if startTime is not null then
strsql_1 := ' and to_char(create_date,'''||pattern||''') >=''' ||startTime|| '''' ;
strsql := strsql || strsql_1 ;
end if ;
if endTime is not null then
strsql_2 := ' and to_char(create_date,'''||pattern||''') <=''' ||endTime|| '''' ;
strsql := strsql || strsql_2 ;
end if ;
if spID >0 then
strsql_3 := ' and black.sp_id = '||spID||'' ;
strsql := strsql || strsql_3 ;
end if ;
execute immediate strsql into v_dataCount;
newBlackCount := newBlackCount + v_dataCount ;
strsql := basicstrsql || strsql_2||strsql_3;
execute immediate strsql into v_dataCount;
blackTotalCount := blackTotalCount + v_dataCount ;
end text;
一个小例子 这是我第一次写存储过程,有很多的不足 ,希望高手能多多评点 ,java小生不胜感激