存储过程中如何实现如下的功能:a integer;
b integer;a:=0;
b:=0;select case 字段1 when 1 then
a:= a +1
when 2 then
b:= b +1
end,
其他字段
from 表
b integer;a:=0;
b:=0;select case 字段1 when 1 then
a:= a +1
when 2 then
b:= b +1
end,
其他字段
from 表
解决方案 »
- 怎样用字典表的数据替换另一个表中某个字段的值?
- sql语句查询 字段内容 是否存在 如果不存在 显示结果
- 调试问题
- 请把忙看看这个存储过程为什么不对。
- 这条SQL怎么写???谢谢
- vb.net通过odbc连接oracle低版本(6。0)中,如何通知不同用户
- 怎样定义一个JOB每隔20分钟执行一下?
- hibernate query.list() 方法为什会卡死
- 客户端配置了监听和服务,但是windows里的服务找不到监听程序...
- 为什么oracle静默安装建库之后,生成的tnsname.ora 文件service_name参数值用的是GDBNAME而不是SID?
- oracle撤销权限问题
- oracle并行查询问题
decode(字段1,1,a+1,2,b+1)
decode(字段1,1,a+1,2,b+1)
a integer;
b integer;
v_字段1 integer;
begin
a := 0;
b := 0;
v_字段1 := 0; select 字段1 into v_字段1 from 表 where rownum <= 1; if v_字段1 = 1 then
a := a + 1;
else
if v_字段1 = 2 then
b := b + 1;
end if;
end if;
dbms_output.put_line('a=' || a);
dbms_output.put_line('b=' || b);
end;
a number(18,0);
b number(18,0);
begin
select sum(decode(字段1,1,1,0)), sum(decode(字段1,2,1,0)) into a, b from 表;
dbms_output.put_line('字段1中,值为1 的记录行数为:'||to_char(a)||' 值为2 的记录行数为:'||to_char(b));
end;
/
declare
a number;
b number;
begin
select count(decode(字段1,1,1)),count(decode(字段1,2,1)) into a,b from tb;
dbms_output.put_line('字段1是1的记录数目有:'||to_char(a)||' '||'字段1是2的记录数目有:'||to_char(b));
end;
select count(*) into b from tb where 字段1=2;