pengdali(大力 V3.0) 请进---急--在线等....................

ineedtostudy 2003-10-12 08:47:01
pengdali(大力 V3.0) :我测试了,出了错误:

存储过程如下:
procedure pro_cx_test(my_cur in out my_cursor) is


-- v_dw char(2) default '03';
sqlstr varchar2(4000);

cursor c_bm is select distinct bm_bm from gdzckp where dw_bm=v_dw;
-- TYPE my_cursor is REF CURSOR;
-- my_cur my_cursor;

begin

for v_bm in c_bm loop
sqlstr:=sqlstr||',sum(decode(bm_bm,'''||v_bm.bm_bm||''',sl,0)) '|| v_bm.bm_bm;
end loop;
--这句做调试用
dbms_output.put_line('select flmc,count(*) 合计'||sqlstr||' from gdzckp where dw_bm='''||v_dw||''' group by flmc');

open my_cur FOR 'select flmc,count(*) 合计'||sqlstr||' from gdzckp where dw_bm='''||v_dw||''' group by flmc';

end pro_cx_test;


错误出现在:
open my_cur FOR 'select flmc,count(*) 合计'||sqlstr||' from gdzckp where dw_bm='''||v_dw||''' group by flmc';

错误信息:
异常详细信息: Oracle.DataAccess.Client.OracleException: ORA-00923: 未找到预期 FROM 关键字 ORA-06512: 在"GDZC.PKG_GDZC_CX", line 238 ORA-06512: 在line 1

dbms_output的结果为:
select flmc,count(*) 合计,sum(decode(bm_bm,'03',sl,0)) 03 from gdzckp where dw_bm='03' group by flmc


我该怎么办?




...全文
72 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ineedtostudy 2003-10-12
  • 打赏
  • 举报
回复
就改那里就可以了
我测试出来了
谢谢!
ineedtostudy 2003-10-12
  • 打赏
  • 举报
回复
只把cursor c_bm is select distinct bm from dali.table1 where dw=indw;中的 dali.table1 改成表一 就可以了吗?
ineedtostudy 2003-10-12
  • 打赏
  • 举报
回复
pengdali(大力 V3.0):我还有个问题
表1
bm mc
bm1 部门1
bm2 部门2
bm3 部门3
bm4 部门4
bm5 部门5

表2
dw bm mc sl je
01 bm1 计算机 1 10000
01 bm1 空调 2 20000
01 bm1 计算机 2 20000
01 bm2 打印机 1 10000
01 bm2 计算机 1 10000
01 bm4 电视机 1 4000
02 bm2 电视机 1 4000
03 bm1 计算机 1 10000
04 bm1 计算机 1 10000


要得到的查询结果是:输入dw 后(例如01)出现下面的结果


合计 部门1 部门2 部门3 部门4 部门5
mc sl je sl je sl je sl je sl je sl je
计算机 4 40000 3 30000 1 10000 0 0 0 0 0 0
空调 2 20000 2 20000 0 0 0 0 0 0 0 0
打印机 1 10000 0 0 1 10000 0 0 0 0 0 0
电视机 1 4000 0 0 0 0 0 0 1 4000 0 0
... .. ..... .. .. .. ...... .. ....


根据输入的dw 不同,查出不同的结果

这个查询的该怎么写呢?也返回的是ref cursor 类型
pengdali 2003-10-12
  • 打赏
  • 举报
回复
不用谢。
我没有QQ,不好意思。
ineedtostudy 2003-10-12
  • 打赏
  • 举报
回复
非常感谢!

有时间来秦皇岛玩
QQ:113308331
pengdali 2003-10-12
  • 打赏
  • 举报
回复
这里你要改一下,因为还有个je列:

create or replace package body dali.packtest as
function f_get_result(indw in varchar2) return my_cursor as
cursor c_bm is select distinct bm from dali.table1 where dw=indw;
my_cur my_cursor;
sqlstr varchar2(4000);
begin
for v_bm in c_bm loop
sqlstr:=sqlstr||',sum(decode(bm,'''||v_bm.bm||''',sl,0)) '|| v_bm.bm||'sl,sum(decode(bm,'''||v_bm.bm||''',je,0)) '|| v_bm.bm||'je';
end loop;
open my_cur FOR 'select mc,count(*) 合计'||sqlstr||' from dali.table1 where dw='''||indw||''' group by mc';
return my_cur;
end;
end;
pengdali 2003-10-12
  • 打赏
  • 举报
回复
对不起,来晚了。
函数:

CREATE OR REPLACE PACKAGE dali.packtest as
TYPE my_cursor is REF CURSOR;
function f_get_result (indw in varchar2) return my_cursor;
end;

create or replace package body dali.packtest as
function f_get_result(indw in varchar2) return my_cursor as
cursor c_bm is select distinct bm from dali.table1 where dw=indw;
my_cur my_cursor;
sqlstr varchar2(4000);
begin
for v_bm in c_bm loop
sqlstr:=sqlstr||',sum(decode(bm,'''||v_bm.bm||''',sl,0)) '|| v_bm.bm;
end loop;
open my_cur FOR 'select mc,count(*) 合计'||sqlstr||' from dali.table1 where dw='''||indw||''' group by mc';
return my_cur;
end;
end;
ineedtostudy 2003-10-12
  • 打赏
  • 举报
回复
我有知道了,是因为我在调用存储过程时,没有将dbms_output去掉
非常感谢你!
ineedtostudy 2003-10-12
  • 打赏
  • 举报
回复
ORA-24338: 未执行语句句柄


这是什么样的错误?怎么修改呀?
ineedtostudy 2003-10-12
  • 打赏
  • 举报
回复
这个问题我知道了,是因为from 前面的03 ,我改过来了

3,491

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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