oracle 动态游标行数,oracle动态游标的简单实现方法
下面就是例子程序
--明细表打印予处理 通用报表:
procedure mx_print_common(pd_id in mx_pd_syn.pd_id%type,
p_pd_mxb_id IN mx_pd_mxb_syn.p_mxb_id%type,
p_dept_no IN sc_mxk.dept_code%type,
p1 sc_bz_syn.bz_code%type,
p2 sc_cjjc_syn.cjjc_code%type,
p3 sc_mxk.warehouse_num%type)
is
sql2 varchar2(500); --存储查询语句
sql3 varchar2(500); --存储查询条件
str1 sc_print_syn.a%type; --存储车间进程
str2 sc_print_syn.b%type; --存储班组(工艺、工序)进程
s_ip sc_print_syn.ip%type;
type cursor_type is ref cursor;
c1 cursor_type; type record_type is record(
pbom_id sc_mxk.pbom_id%type
);
r_c1 record_type; /*
注意上面红色的两行和蓝色的两行
红色的两行定义一个游标
蓝色的两行定义一个游标中将要返回的数据的数据结构
*/
cursor c2(p_pbom_id sc_mxk.pbom_id%type) is
select a.dd_count,b.gx_name,c.bz_name,d.cjjc_name
from sc_p_gx_syn a,sc_gx_syn b,sc_bz_syn c,sc_cjjc_syn d
where pbom_id = p_pbom_id
and a.gx_code=b.gx_code(+) and b.dept_code=p_dept_no
and a.bz_code=c.bz_code(+) and b.dept_code=p_dept_no
and a.cjjc_code=d.cjjc_code(+) and b.dept_code=p_dept_no;
r_c2 c2%rowtype;
BEGIN
s_ip :=sys_context('USERENV','IP_ADDRESS');
delete from sc_print_syn where ip=s_ip and p_id=pd_id;
commit;
--下面开始构造查询语句
sql2:='select distinct a.pbom_id from sc_mxk a';
sql3:=' where a.p_id=' || pd_id || ' and a.dept_code= ''' || p_dept_no || '''';
if p_pd_mxb_id >0 then
sql2:=sql3 || ',mxk c ';
sql3:=sql3 || ' and c.m_mxb_id= ' || p_pd_mxb_id || ' and a.mxb_id = c.mxb_id';
end if;
if p1 is not null then
sql2:=sql2 || ',sc_p_gx_syn b';
sql3:=sql3 || ' and a.pbom_id=b.pbom_id and b.bz_code = ''' || p1 || '''';
end if;
if p2 is not null then
sql2:=sql2 || ',sc_p_gx_syn b';
sql3:=sql3 || ' and a.pbom_id=b.pbom_id and b.cjjc_code = ''' || p2 || '''';
end if;
if p3 is not null then
sql3:=sql3 || ' and a.warehouse_num = ''' || p3 || '''';
end if;
sql2:=sql2 || sql3;
--打开动态游标,再往下就都一样了
open c1 for sql2;
loop
fetch c1 into r_c1;
exit when c1%notfound;
str1:='';
str2:='';
--打开工序表进行处理
open c2(r_c1.pbom_id);
loop
fetch c2 into r_c2;
exit when c2%notfound; --没有记录退出
if r_c2.cjjc_name is not null then
str1 :=str1 || to_char(r_c2.cjjc_name);
end if;
if r_c2.bz_name is not null then
str2 := str2 || r_c2.bz_name || to_char(r_c2.dd_count);
elsif r_c2.gx_name is not null then
str2 := str2 || to_char(r_c2.gx_name) || to_char(r_c2.dd_count);
end if;
end loop;
close c2;
insert into sc_print_syn(a,b,ip,p_id,r_id)
values(str1,str2,s_ip,pd_id,r_c1.pbom_id);
COMMIT;
end loop;
close c1;
END mx_print_common;
当然,实现的方法一定很多,甚至可以用隐式游标。但是隐式游标中用动态查询语句也要费一些周折的。
作者:Northsnow
电子邮件:northsnow@163.com
blog:http://blog.csdn.net/precipitant
posted on 2008-05-27 09:17 xzc 阅读(10438) 评论(3) 编辑 收藏 所属分类: Oracle
oracle 动态游标行数,oracle动态游标的简单实现方法相关推荐
- eclipse代码量统计插件_Android Studio 代码行数统计插件Statistic的简单使用
在项目开发过程中,有时候需要统计代码行数(比如组长想关心一下你的代码量,或者要申请软件著作权时),需要统计的文件类型主要是 .java..xml..kt等,已经有人开发好相关插件了,如果你是用Andr ...
- 代码行数越少就越“简单”吗?
我们先一起看一个例子.下面这三段代码可以实现同样一个功能:检查输入的字符串 ipAddress 是否是合法的 IP 地址. 一个合法的 IP 地址由四个数字组成,并且通过"."来进 ...
- oracle查询游标行数,如何查找Oracle PL/SQL游标中的记录数量?
NB:我刚才重读你的问题..你要失败的.如果只有1个记录.. 我会后在某一时刻有新的更新.. ,让我们开始在这里.. 从的Oracle®数据库PL/SQL用户指南和参考 10g第2版(10.2) 型号 ...
- oracle查询表占用空,Oracle 表的行数、表占用空间大小,列的非空行数、列占用空间大小 查询...
--表名,表占用空间大小(MB),行数 select table_name, round(num_rows * avg_row_len /1024/1024, 8) as total_len, num ...
- oracle查询最大并发数,oracle最大并发数查看
查看oracle的最大并发数限制,可是查看v$license视图 v$license视图: 里面记录了Oracle最大的并发数以及当前用户的连接数, 官方文档有如下描述: This view cont ...
- linux 合计文件大小,linux下对符合条件的文件大小和行数做汇总统计的简单命令...
(1)统计当前目录下的 *txt 文件 du -c -h *txt (2)统计当前目录下的 *txt 文件, 并求出总大小 du *txt |awk 'BEGIN{count=0;size=0;} \ ...
- oracle中sql行数的计算,Oracle技术网—如何利用DBMS_SQL包和游标计算当前用户下所有表的行数...
实现方法: SQL> conn scott/tiger SQL> set serveroutput on size 1000000 SQL> SQL> DECLARE 2 t_ ...
- oracle指定查询行数
oracle使用虚列rownum可以查询到指定数字之间的记录数 第一行的rownum=1 查询前五条记录. -----此条SQL类似于mysql的limit函数 select * from 表名 wh ...
- oracle数据导出限定行数,oracle exp 导出数据最大行数是否有限制
匿名用户 1级 2012-10-17 回答 exp 没有行数限制,你可以通过设置参数ROWS试一下. 可以通过输入跟有各种参数的 EXP 命令来控制导出 的运行方式.要指定参数, 您可以使用关键字: ...
最新文章
- UI培训教程分享:Ui设计的细节规范有哪些需要注意?
- 对 Entity 的初步构思
- Stream流中的常用方法_filter
- Linux gcc编译c/c++基本过程
- 4位先行进位加法器_行波进位/超前进位加法器详解
- python 异步与io
- python机器学习常用包下载安装以及使用案例汇总
- C语言 结构体练习之投票
- Java基础学习总结(41)——JPA常用注解
- Visual C++中动态链接库技术浅谈
- 多线程,异步委托,同步委托几种方式的区别
- 【三次握手、四次挥手流程】及【长短链接区别】
- 深度学习中的梯度下降算法
- mvc:annotation-driven /注解意义
- Google 2018 更新内容
- 阿里玄难:面向不确定性的软件设计几点思考
- Simulink提速方式
- Java可以应用到哪些领域?
- c语言图片处理函数库,C语言图形开发库函数graphics.doc
- 第二阶段--团队冲刺--第五天
热门文章
- 使用EntityFrameworkCore实现Repository, UnitOfWork,支持MySQL分库分表
- 在离线环境中发布.NET Core至Windows Server 2008
- 红帽、微软和 Codenvy 联合推出语言服务器协定(Language Server Protocol,LSP)项目
- 用 Visual Studio Code 在 macOS 上创建首个 ASP.NET Core 应用程序
- TFS2015的CI集成
- rest_framework12:多登陆方式与自动签发token/配置过期时间
- Android WebView 图片超出宽度自适应,点击查看大图
- 【EPS精品教程】基于DOM和DSM创建垂直模型、加载垂直模型
- 用VBA得到EXCEL表格中的行数和列数
- linux之systemctl设置自定义服务