create procedure del_proc (a in varchar2,b in varchar2,c in number,d in varchar2) begin if a is null then if b=0 then delete from table1 where C=c and D=d and B='1' and B='2'; end if;
if b!=0 then delete from table1 where C=c and D=d and B=b; end if; end if;
if a is not null then if b=0 then delete from table1 where C=c and D=d and B='1' and B='2' and A=a; end if;
if b!=0 then delete from table1 where C=c and D=d and B=b and A=a; end if; end if; end del_proc
楼上的B='1' and B='2' 不是and 应该是or 这样要这样吧(B='1'or B='2')? 如果有返回值的话是在delete语句的后面加上 return ..吗
create function del_proc(a in varchar2,b in varchar2,c in number,d in varchar2) begin if a is null then if b=0 then delete from table1 where C=c and D=d and (B=1 or B=2); end if;
if b!=0 then delete from table1 where C=c and D=d and B=b; end if; end if;
if a is not null then if b=0 then delete from table1 where C=c and D=d and (B=1 or B=2) and A=a; end if;
if b!=0 then delete from table1 where C=c and D=d and B=b and A=a; end if; end if; return 0; --不一定非得给返回值吧?? end del_proc
我把问题说一下:
写一个function,四个参数,a ->varchar ,b->varchar,c ->number ,d->varchar
1 、a参数=null时候:
1)b如果是0 ,删除数据表中一下条件的数据
C(字段名)=c
D(字段名v)=d
B(字段名) = 1 和B(字段名) =2 2)b如果不是0 ,删除数据表中一下条件的数据
C(字段名)=c
D(字段名v)=d
B(字段名) = b
2、a参数!=null时候:
1)b如果是0 ,删除数据表中一下条件的数据
C(字段名)=c
D(字段名v)=d
B(字段名) = 1 和B(字段名) =2
A(字段名)=a 2)b如果不是0 ,删除数据表中一下条件的数据
C(字段名)=c
D(字段名v)=d
B=b
A(字段名)=a
请问这个函数怎么写?
begin
if a is null then
if b=0 then
delete from table1 where C=c and D=d and B='1' and B='2';
end if;
if b!=0 then
delete from table1 where C=c and D=d and B=b;
end if;
end if;
if a is not null then
if b=0 then
delete from table1 where C=c and D=d and B='1' and B='2' and A=a;
end if;
if b!=0 then
delete from table1 where C=c and D=d and B=b and A=a;
end if;
end if;
end del_proc
这样要这样吧(B='1'or B='2')?
如果有返回值的话是在delete语句的后面加上
return ..吗
begin
if a is null then
if b=0 then
delete from table1 where C=c and D=d and (B=1 or B=2);
end if;
if b!=0 then
delete from table1 where C=c and D=d and B=b;
end if;
end if;
if a is not null then
if b=0 then
delete from table1 where C=c and D=d and (B=1 or B=2) and A=a;
end if;
if b!=0 then
delete from table1 where C=c and D=d and B=b and A=a;
end if;
end if;
return 0; --不一定非得给返回值吧??
end del_proc
Good luck for you!