Oracle 查询,返回记录集,不是用游标,不用创建临时表
2012-09-28 14:23
495 查看
1.首先要创建一个类型集合;
create or replace type row_month_report as object---声明一种类型
(
m_month varchar2(30),
m_SluiceName varchar2(30),
m_OneSluiceCount number,
m_TwoSluiceCount number,
m_OneUpEmptyCount number,
m_OneDownemptyCount number,
m_TwoUpemptyCount number,
m_TwoDownemptyCount number,
------------------------这是写要返回的字段集变量
)
2. create or replace type table_month_report as table of row_month_report;-----把类型当作表使用
3. 编写Oracle 方法:
create or replace function fun_MontnReport(SLUICEID IN VARCHAR2,
D in VARCHAR2) return table_month_report ---返回自定义的类型
pipelined as
vv row_month_report;
m_SluiceName varchar2(30);
daychar VARCHAR2(50); --日期
yearchar VARCHAR2(50); --年份
m_OneSluiceCount number := 0;
m_TwoSluiceCount number := 0;
m_OneUpEmptyCount number := 0;
m_OneDownemptyCount number := 0;
m_TwoUpemptyCount number := 0;
m_TwoDownemptyCount number := 0;
begin
---查询语句,并把值赋给变量如:
select nvl(sum(t.SLUICECOUNT), 0)
into m_OneSluiceCount
from sluicedispatch t
where to_char(t.overtime, 'YYYY-MM') = daychar
and t.sonsluiceoid = '1#'
and t.sluiceoid = SLUICE; --1#闸运行闸次
.....................
4.最后把查到的值赋给自定义的类型( 就相当于给表格插入数据一样)
vv:=row_month_report(
daychar,
m_SluiceName,
m_OneSluiceCount,
m_TwoSluiceCount,
m_OneUpEmptyCount,
m_OneDownemptyCount,
m_TwoUpemptyCount,
m_TwoDownemptyCount
.........................
)values
(
daychar,
m_OneSluiceCount ,
m_TwoSluiceCount ,
m_OneUpEmptyCount
m_OneDownemptyCount ,
m_TwoUpemptyCount ,
m_TwoDownemptyCount
...............
);
pipe row(vv);
return;
end ;
create or replace type row_month_report as object---声明一种类型
(
m_month varchar2(30),
m_SluiceName varchar2(30),
m_OneSluiceCount number,
m_TwoSluiceCount number,
m_OneUpEmptyCount number,
m_OneDownemptyCount number,
m_TwoUpemptyCount number,
m_TwoDownemptyCount number,
------------------------这是写要返回的字段集变量
)
2. create or replace type table_month_report as table of row_month_report;-----把类型当作表使用
3. 编写Oracle 方法:
create or replace function fun_MontnReport(SLUICEID IN VARCHAR2,
D in VARCHAR2) return table_month_report ---返回自定义的类型
pipelined as
vv row_month_report;
m_SluiceName varchar2(30);
daychar VARCHAR2(50); --日期
yearchar VARCHAR2(50); --年份
m_OneSluiceCount number := 0;
m_TwoSluiceCount number := 0;
m_OneUpEmptyCount number := 0;
m_OneDownemptyCount number := 0;
m_TwoUpemptyCount number := 0;
m_TwoDownemptyCount number := 0;
begin
---查询语句,并把值赋给变量如:
select nvl(sum(t.SLUICECOUNT), 0)
into m_OneSluiceCount
from sluicedispatch t
where to_char(t.overtime, 'YYYY-MM') = daychar
and t.sonsluiceoid = '1#'
and t.sluiceoid = SLUICE; --1#闸运行闸次
.....................
4.最后把查到的值赋给自定义的类型( 就相当于给表格插入数据一样)
vv:=row_month_report(
daychar,
m_SluiceName,
m_OneSluiceCount,
m_TwoSluiceCount,
m_OneUpEmptyCount,
m_OneDownemptyCount,
m_TwoUpemptyCount,
m_TwoDownemptyCount
.........................
)values
(
daychar,
m_OneSluiceCount ,
m_TwoSluiceCount ,
m_OneUpEmptyCount
m_OneDownemptyCount ,
m_TwoUpemptyCount ,
m_TwoDownemptyCount
...............
);
pipe row(vv);
return;
end ;
相关文章推荐
- Oracle 查询,返回记录集,不是用游标,不用创建临时表----完整版
- oracle如何 查询 创建 执行存储过程及游标的作用
- Oracle 通过触发器 来创建 同步临时表 及处理 通过 自治事务 来解决 查询 基表的问题
- Oracle 使用函数 function查询数据返回游标
- oracle函数返回结果集(动态查询Sql并定义游标)
- Java调用oracle存储过程通过游标返回临时表数据
- Oracle PLSQL Demo - 15.强类型REF游标[预先指定查询类型与返回类型]
- oracle使用游标让存储过程返回记录集
- Oracle PLSQL Demo - 16.弱类型REF游标[没有指定查询类型,已指定返回类型]
- Java调用oracle存储过程通过游标返回临时表数据
- Java调用oracle存储过程通过游标返回临时表数据
- C#里使用Oracle提供的Oracle.DataAccess 返回包里的记录集游标,含Oralce里的分页包代码
- oracle函数返回结果集(动态查询Sql并定义游标)
- oracle 游标 返回查询结果集
- Oracle PLSQL Demo - 20.弱类型REF游标[没有指定查询类型,也不指定返回类型]
- oracle 中 Function 传参数 查询传参数表总数,返回 总数
- 【转】 oracle临时表-优化查询速度
- oracle-创建存储过程、函数、包、游标、视图
- SqlServer与Oracle创建临时备份表数据的语句区别
- oracle 用函数查询怎么直接返回一个表