热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

菜鸟请教oracle存储过程的问题,急盼高手解答

我的存储过程统计若干值并写入数据库,我是这样写的:createorreplaceproceduremypro(xzqhinvarchar2,)asbegininser
我的存储过程统计若干值并写入数据库,我是这样写的:
create or replace procedure mypro(xzqh in varchar2,...)
as
begin
insert into mytable (field1,field2....) values
(
(select count(kcbh) from mytable1 where instr(kcbh,xzqh)>0 ),
...
);
commit;
end;
在asp调用这个存储过程时候,其他字段都能正确统计到,惟独field1的值始终是0,
在表mytable1里的kcbh字段的值是"k210105101200600001"之类,我传入的参数xzqh的值是"210105101",但是始终得不到正确结果(已知统计结果肯定不是0),请问我到底错在哪里,请高手指点,解决即给分.(我已经为此郁闷到凌晨4点多了)

12 个解决方案

#1


完整的贴出来

#2


就上面的东西看不出错误来

#3


执行select count(kcbh) from mytable1 where instr(kcbh,'210105101')>0的结果是大于0吗?存储过程中不用参数直接写
(select count(kcbh) from mytable1 where instr(kcbh,'210105101')>0),
看看是否能写入值。

#4


谢谢匆匆过客的提示,问题已经解决了。昨晚脑筋短路,忘记了在mytable1里本来就有xzqh这个字段,所以使用它作为传入的参数名,就出错了,害得我白忙活了大半个晚上,希望其他新手引以为戒。现在出现这样的问题,我在oracle9i下调试正常的存储过程,放到8i下始终不能编译成功,是不是版本差异啊,附上相关信息,恳请高手指点。
存储过程是:
create or replace procedure rpt104701pro
(
mydanwei in varchar2,
tjsjfrom in date,
tjsjto in date,
strajlb in varchar2,
mycode in varchar2,
rpt_sq in varchar2,
mydanweiname in varchar2,
myxzqh in varchar2
)
as
begin
insert into rpt104701 
(
danwei,user_code,rpt_sq,
COL1,
COL2,
COL3,
COL4,
COL5,
COL6,
COL7,
COL8,
COL9,
COL10,
COL11
)
 values 
(mydanweiname,mycode,rpt_sq,
--COL1
(select count(ajbh) from ajslb where instr(ajbh,myxzqh)=2 and (state='02' or state='03') and  fasjcz between tjsjfrom and tjsjto and instr(strajlb,ab1)>0),
--COL2
(select count(xc_kcbh) from xc_main_info where xc_kcdw=mydanwei and xc_scbz='1' and xc_kcrq between tjsjfrom and tjsjto and instr(strajlb,xc_ajlb)>0),
--COL3
(select count(distinct(wz_kcbh)) from view_wz_xc where xc_kcdw=mydanwei and xc_scbz='1' and xc_kcrq between tjsjfrom and tjsjto and instr(strajlb,xc_ajlb)>0),
--COL4
(select count(xc_kcbh) from xc_main_info where xc_kcdw=mydanwei and xc_ajfxbgs>0 and xc_kcrq between tjsjfrom and tjsjto and instr(strajlb,xc_ajlb)>0),
--COL5
(select count(xc_kcbh) from xc_main_info where xc_kcdw=mydanwei and xc_xccls>=3 and xc_kcrq between tjsjfrom and tjsjto and instr(strajlb,xc_ajlb)>0),
--COL6
(select count(distinct(wz_kcbh)) from view_wz_xc where xc_kcdw=mydanwei and wz_zt<>'101007' and xc_kcrq between tjsjfrom and tjsjto and instr(strajlb,xc_ajlb)>0),
--COL7
(select count(xc_kcbh) from xc_main_info where xc_kcdw=mydanwei and xc_jyjls>0 and xc_kcrq between tjsjfrom and tjsjto and instr(strajlb,xc_ajlb)>0),
--COL8
(select count(ws_kcbh) from ws_info where ws_jydw=mydanwei and (ws_fyhjjl='101702' or ws_fyhjjl='101703') and ws_kcbh like '%H%' and ws_zt<>'101202' and ws_lrsj between tjsjfrom and tjsjto),
--COL9
(select count(user_code) from userlist where dpt_code=mydanwei and (engage_major='100401' or engage_major='100402' or engage_major='100403')),
--COL10
(select count(xc_kcbh) from xc_main_info where xc_kcdw=mydanwei and xc_scbz='1' and xc_kcrq between tjsjfrom and tjsjto),
--COL11
((select count(ws_kcbh) from ws_info where ws_jydw=mydanwein and ws_zt<>'101202' and ws_kcbh like '%H%' and ws_lrsj between tjsjfrom and tjsjto)+(select count(fy_jybh) from fy_info where fy_jydw=mydanwei and fy_jybh like '%S%' and fy_jyrq between tjsjfrom and tjsjto)));
commit;
end;
在oracle8i下编译时,出错,下面是pl/sql的错误报告:
32 PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:

   ( - + mod not null others 
     avg
   count current exists max min prior sql stddev sum variance
   execute forall time timestamp interval date
   
    
 
32 PLS-00103: Encountered the symbol "," when expecting one of the following:

   ; return returning and or
 
52 PLS-00103: Encountered the symbol "+" when expecting one of the following:

   ) with intersect minus order union
The symbol "intersect was inserted before "+" to continue.
 
52 PLS-00103: Encountered the symbol ")" when expecting one of the following:

   , ; for 
    group having intersect
   minus order start union where connect 
急盼高手赐教。

#5


自己顶一下,高手救命啊

#6


create or replace procedure mypro(xzqh in varchar2,...)
as
begin
insert into mytable (field1,field2....) values
(
(select count(kcbh) from mytable1 where instr(kcbh,xzqh)=2), //你把此处改成这样试试
...
);
commit;
end;

#7


谢谢oklsl,前面的插入数据库问题已将解决了,现在的问题是,我在oracle9i下调试正常的存储过程,放到8i下始终不能编译成功,存储过程代码以及出错信息我在前面已经贴出来了,请大家帮忙看看好不好。

#8


一定要顶起来啊,高手们都还在睡觉吗?

#9


难道这个问题很难么?自己再顶

#10


估计是8i不支持insert into ... values中有子查询,把各个子查询的值先保存到变量中再插入。

#11


请问,在存储过程中,如何把“查询的值先保存到变量中”啊

#12


create or replace procedure rpt104701pro
(
mydanwei in varchar2,
tjsjfrom in date,
tjsjto in date,
strajlb in varchar2,
mycode in varchar2,
rpt_sq in varchar2,
mydanweiname in varchar2,
myxzqh in varchar2
)
as
  v_col1 number;
  v_col2 number;
  ...
begin
  select count(ajbh) into v_col1 from ajslb where instr(ajbh,myxzqh)=2 and (state='02' or state='03') and  fasjcz between tjsjfrom and tjsjto and instr(strajlb,ab1)>0;
  ...
insert into rpt104701 
(
danwei,user_code,rpt_sq,
COL1,
COL2,
COL3,
COL4,
COL5,
COL6,
COL7,
COL8,
COL9,
COL10,
COL11
)
 values 
(mydanweiname,mycode,rpt_sq,v_col1,...);
commit;
end;

推荐阅读
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • Oracle分析函数first_value()和last_value()的用法及原理
    本文介绍了Oracle分析函数first_value()和last_value()的用法和原理,以及在查询销售记录日期和部门中的应用。通过示例和解释,详细说明了first_value()和last_value()的功能和不同之处。同时,对于last_value()的结果出现不一样的情况进行了解释,并提供了理解last_value()默认统计范围的方法。该文对于使用Oracle分析函数的开发人员和数据库管理员具有参考价值。 ... [详细]
  • 本文详细介绍了Spring的JdbcTemplate的使用方法,包括执行存储过程、存储函数的call()方法,执行任何SQL语句的execute()方法,单个更新和批量更新的update()和batchUpdate()方法,以及单查和列表查询的query()和queryForXXX()方法。提供了经过测试的API供使用。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • 学习SLAM的女生,很酷
    本文介绍了学习SLAM的女生的故事,她们选择SLAM作为研究方向,面临各种学习挑战,但坚持不懈,最终获得成功。文章鼓励未来想走科研道路的女生勇敢追求自己的梦想,同时提到了一位正在英国攻读硕士学位的女生与SLAM结缘的经历。 ... [详细]
  • PHP图片截取方法及应用实例
    本文介绍了使用PHP动态切割JPEG图片的方法,并提供了应用实例,包括截取视频图、提取文章内容中的图片地址、裁切图片等问题。详细介绍了相关的PHP函数和参数的使用,以及图片切割的具体步骤。同时,还提供了一些注意事项和优化建议。通过本文的学习,读者可以掌握PHP图片截取的技巧,实现自己的需求。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • IB 物理真题解析:比潜热、理想气体的应用
    本文是对2017年IB物理试卷paper 2中一道涉及比潜热、理想气体和功率的大题进行解析。题目涉及液氧蒸发成氧气的过程,讲解了液氧和氧气分子的结构以及蒸发后分子之间的作用力变化。同时,文章也给出了解题技巧,建议根据得分点的数量来合理分配答题时间。最后,文章提供了答案解析,标注了每个得分点的位置。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
author-avatar
手机用户2502932937
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有