新手提问:最简单的存储过程问题!

zsp0010 2006-06-05 06:03:01
存储过程
create or replace procedure UpdateDivCell
(intFstRowId in Integer,
intBudgetId in Integer,
gSetid In Integer,
gYear In Integer,
spdivrowid Out Number
)

Is

SQLText varchar2(2048);
begin
SQLText:=' SELECT a.DivRowid, b.name bname, b.Code BCode FROM DivPay a LEFT JOIN temp_Budgetsection b ON a.year = b.year AND a.bid = b.bid';

If intFstRowId <> 0 Then
SQLText:=SQLText|| 'and a.BudgetId = '||0|| 'and a.FstRowId = '||intFstRowId;

Else
SQLText:=SQLText|| 'and a.BudgetId = '||0|| 'and a.FstRowId= '||intBudgetId;
End If;
SQLText:='begin '||SQLText ||';end;';
execute immediate SQLText;

end UpdateDivCell;

我想用spdivrowid 这个值返回查询结果里面的divrowid字段值,这个该怎么修改?
这是小弟第一次写存储过程,感激了!
...全文
201 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
沝林 2006-06-07
  • 打赏
  • 举报
回复
返回多条记录要用集合类型变量接受返回值,如:
create ... procedure ..
Is
--声明集合类型
type myType is table of DivPay.DivRowid %TYPE;
v_myType myType;
begin
...

EXECUTE IMMEDIATE 'SELECT DivRowid FROM DivPay'
BULK COLLECT INTO myType;
...
end;
47522341 2006-06-06
  • 打赏
  • 举报
回复
要确保查询语句只返回1条记录
沝林 2006-06-06
  • 打赏
  • 举报
回复
返回多个变量值只要将变量跟查询字段对应上就可以了,返回1个变量默认取第一个字段的值
execute immediate SQLText into v1,v2,v3
沝林 2006-06-06
  • 打赏
  • 举报
回复
--SQLText:='begin '||SQLText ||';end;'; -- 这句去掉,不需要
execute immediate SQLText into spdivrowid; -- 这里加上into 子句,另外要确保查询语句只返回1条记录
zsp0010 2006-06-06
  • 打赏
  • 举报
回复
UP
zsp0010 2006-06-06
  • 打赏
  • 举报
回复
如果返回多条记录的话
那这个游标该怎么写?
zsp0010 2006-06-06
  • 打赏
  • 举报
回复
谢谢
已经明白了

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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