高手们帮忙解决一下吧,一定给足分!!!

zhangxf 2003-08-30 12:59:49
我在一个包里写了一个存储过程,执行的那些sql语句,提示说“无效的列名”,我通过调试知道是st1,st2的问题,看来oracle还无法识别st1,st2,那么我该如何来引用这两个计算而得的日期变量呢,非常急迫啊,高手们救我,谢谢一定加分!!!

CREATE OR REPLACE package BODY ZXF.Necktie is
-- NecktieList is cursor variable
PROCEDURE sp_Necktie_GetSaleList(s_date1 in zxf.hxda.hxmc%type,s_date2 in zxf.hxda.hxmc%type, NecktieList out sale_outList)
is
begin
--写SQL语句获得需要的变量值!!!
select sfrq into st1 from zxf.sfjl where sfrq <=to_date(s_date1, 'yyyy/mm/dd hh24:mi:ss') and rownum = 1 order by sfrq desc;
select sfrq into st2 from zxf.sfjl where sfrq <=to_date(s_date2, 'yyyy/mm/dd hh24:mi:ss') and rownum = 1 order by sfrq desc;

OPEN NecktieList
FOR 'select a.hxbm as hxbm,
(select nvl(sum(inum),0) from zxf.sfjl where sfrq>= st1 and sfrq <=st2 and sflb=1 and hxbm=a.hxbm) as xsl
from zxf.hxda a
order by hxbm,xsl desc';
end;
...全文
33 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangxf 2003-09-01
  • 打赏
  • 举报
回复
非常非常感谢:

onejune4450(中文字符)
beckhambobo(beckham)
我的问题已经解决了:
(select nvl(sum(inum),0) from zxf.sfjl where sfrq<= to_date('''||to_char(st2,'yyyy-mm-dd')||''',''yyyy-mm-dd'') and sflb=1 and hxbm=a.hxbm)
onejune4450 2003-09-01
  • 打赏
  • 举报
回复
写错了
for 'select hxbm,inum from zxf.sfjl where to_char(sfrq,''YYYY-MM-DD'')<=to_char('''||ct1||''',''YYYY-MM-DD''), and sflb=1';
------------''
onejune4450 2003-09-01
  • 打赏
  • 举报
回复
for 'select hxbm,inum from zxf.sfjl where to_char(sfrq,''YYYY-MM-DD'')<=to_char('''||ct1||',''YYYY-MM-DD''), and sflb=1';
zhangxf 2003-09-01
  • 打赏
  • 举报
回复
thanks to :beckhambobo(beckham)
'select a.hxbm,(select sum(nvl(inum,0)) from zxf.sfjl where sfrq>= to_date(''2010-09-09'',''yyyy-mm-dd'') and sfrq <=to_date(''2000-09-09'',''yyyy-mm-dd'') and sflb=1 and hxbm=a.hxbm) xsl
from zxf.hxda a
order by hxbm,xsl desc';
你的方法是对的!!!
现在问题是变量还是不行,放进去就说:
ORA-01841: (全)年度值必须介于 -4713 和 +9999 之间,且不为 0


onejune4450 2003-09-01
  • 打赏
  • 举报
回复
测试一下:
把yyyy/mm/dd 换成 YYYY-MM-DD

(select nvl(sum(inum),0) from zxf.sfjl
where sfrq<= '||to_date('||2010-09-09||','YYYY-MM-DD')||'
and sfrq>= '||to_date('||2000-09-09||','YYYY-MM-DD')||'
and sflb=1 and hxbm=a.hxbm)
zhangxf 2003-09-01
  • 打赏
  • 举报
回复
老大快帮帮忙啊,现在我把它写成最简单的,什么都不处理,就是引用日期变量:
for 'select hxbm,inum from zxf.sfjl where sfrq<='||ct1||' and sflb=1';
说:ORA-00933: SQL 命令未正确结束!!!
救命啊,到底怎么引用日期变量啊
难道没有一个人搞过吗?????
beckhambobo 2003-09-01
  • 打赏
  • 举报
回复
'select a.hxbm,(select sum(nvl(inum,0)) from zxf.sfjl where sfrq>= to_date(''2010-09-09'',''yyyy-mm-dd'') and sfrq <=to_date(''2000-09-09'',''yyyy-mm-dd'') and sflb=1 and hxbm=a.hxbm) xsl
from zxf.hxda a
order by hxbm,xsl desc';
zhangxf 2003-09-01
  • 打赏
  • 举报
回复
我把那条语句换成这样:
(select nvl(sum(inum),0) from zxf.sfjl where sfrq<= '||to_date('||2010-09-09||','yyyy/mm/dd hh24:mi:ss')||' and sfrq>= '||to_date('||2000-09-09||','yyyy/mm/dd hh24:mi:ss')||' and sflb=1 and hxbm=a.hxbm)
提示错误变成:
ORA-01841: (全)年度值必须介于 -4713 和 +9999 之间,且不为 0
beckhambobo 2003-09-01
  • 打赏
  • 举报
回复
select a.hxbm,(select sum(nvl(inum,0)) from zxf.sfjl where sfrq>=... and sfrq <=... and sflb=1 and hxbm=a.hxbm) xsl from zxf.hxda a order by hxbm,xsl desc;
省略号给它放几个值去。看看这条语句能不能执行
zhangxf 2003-09-01
  • 打赏
  • 举报
回复
还是有问题啊,出错提示还是:缺少右括号
beckhambobo 2003-09-01
  • 打赏
  • 举报
回复
select sfrq into st1 from (select * from zxf.sfjl where sfrq <=to_date(s_date1, 'yyyy/mm/dd hh24:mi:ss') order by sfrq desc) where rownum = 1;

select sfrq into st2 from (select * from zxf.sfjl where sfrq <=to_date(s_date2, 'yyyy/mm/dd hh24:mi:ss') order by sfrq desc) where rownum = 1;
zhangxf 2003-09-01
  • 打赏
  • 举报
回复
to: beckhambobo(beckham)
我已经按照你的'||st1||'用了,但是出现错误“缺少右括号”
我用字符型的变量如此引用的话,绝对没有问题的,所以现在的问题就剩下日期类型的引用了
谢谢,请再帮我吧
qinhaichun 2003-08-31
  • 打赏
  • 举报
回复
由 st1 改成 ZXF.Necktie.st1 试试?
csuxiong 2003-08-31
  • 打赏
  • 举报
回复
同上
zhangxf 2003-08-30
  • 打赏
  • 举报
回复
包头在这里:
CREATE OR REPLACE package ZXF.Necktie is

--Public type declarations, cursor variable
type sale_outList is ref cursor;
--变量定义:
ct1 zxf.csch.hzrq%type;
ct2 zxf.csch.hzrq%type;

st1 zxf.sfjl.sfrq%type;
st2 zxf.sfjl.sfrq%type;
v_sql varchar2(1000);

PROCEDURE sp_Necktie_GetSaleList(s_date1 in zxf.hxda.hxmc%type,s_date2 in zxf.hxda.hxmc%type, NecktieList out sale_outList);

end Necktie;
/
所以现在的问题聚集在日期列的引用,出了问题
jiezhi(浪子) 高手再帮我一把
jiezhi 2003-08-30
  • 打赏
  • 举报
回复
包頭里面沒有看到你的聲明啊?
zhangxf 2003-08-30
  • 打赏
  • 举报
回复
老大们,帮忙啊!!!
zhangxf 2003-08-30
  • 打赏
  • 举报
回复
我已经在包头里声明了啊,还有我用:st1的话,运行非常的慢,错误提示变为:javax.servlet.ServletException: ORA-00600: 内部错误代码,自变量: [15212], [1], [], [], [], [], [], []
armu80830 2003-08-30
  • 打赏
  • 举报
回复
楼上说得对,你没有定义 st1 和 st2 ,将它们声明为date类型变量
jiezhi 2003-08-30
  • 打赏
  • 举报
回复
st1,st2你都沒有聲明
加载更多回复(2)

17,377

社区成员

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

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