新手问题,求助

mugua604 2011-09-12 04:35:58
declare
v_cnt int;
begin
execute immediate 'select tt from duald WHERE col='''A'''' into v_cnt;
end;


当语句没值的时候,我需要V_CNT=0。。怎么处理。不需要抓错误。。如果抓了错误。
下面的代码以V_CNT=0想继续跑.

怎么处理!
...全文
149 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
再定义一个变量,然后select count(*) into 变量 from duald WHERE col='''A''''
然后通过变量if判断v_cnt的值
mugua604 2011-09-12
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 benchim888 的回复:]
SQL code

declare
v_cnt int;
begin
begin
execute immediate 'select tt from duald WHERE col='''A'''' into v_cnt;
exception
when no_data_found then
v_cnt := 0;
end;

……
[/Quote]

在同一个PROC怎么处理呢。。
mugua604 2011-09-12
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 java3344520 的回复:]
v_cnt int;
添加默认值即可
v_cnt int:=0;
[/Quote]

但提示

ORA-01403: 未找到数据
ORA-06512: 在 "SYS.EVSYS_LIST", line 142
ORA-06512: 在 line 2
iqlife 2011-09-12
  • 打赏
  • 举报
回复
v_cnt int;
添加默认值即可
v_cnt int:=0;
BenChiM888 2011-09-12
  • 打赏
  • 举报
回复

declare
v_cnt int;
begin
begin
execute immediate 'select tt from duald WHERE col='''A'''' into v_cnt;
exception
when no_data_found then
v_cnt := 0;
end;

begin
execute immediate 'select tt from duald WHERE col='''B'''' into v_cnt;
exception
when no_data_found then
v_cnt := 1;
end;
end;

mugua604 2011-09-12
  • 打赏
  • 举报
回复
declare
v_cnt int;
begin
begin
execute immediate 'select tt from duald WHERE col='''A'''' into v_cnt;

execute immediate 'select tt from duald WHERE col='''B'''' into v_cnt;
exception
when no_data_found then
v_cnt := 0;
end;
end;


如果B的条件需要v_cnt:=1?怎么办??
BenChiM888 2011-09-12
  • 打赏
  • 举报
回复

declare
v_cnt int;
begin
begin
execute immediate 'select tt from duald WHERE col='''A'''' into v_cnt;
exception
when no_data_found then
v_cnt := 0;
end;
end;

dawugui 2011-09-12
  • 打赏
  • 举报
回复
execute immediate 'select nvl(tt,0) from duald WHERE col='''A'''' into v_cnt;

17,382

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧