oracle返回表id,Oracle 函数返回表实例2种写法实例
--注:用ps/sql工具执行语句
--一合同预算状态函数
--1.
drop type htjs_business_row
drop type htjs_business_state_row_type
CREATE OR REPLACE type htjs_business_state_row_type as object(bissid VARCHAR2(20),businessState varchar2(50));
CREATE OR REPLACE type htjs_business_row as table of htjs_business_state_row_type;
--2.
CREATE OR REPLACE
function fun_htjs_business_state return htjs_business_row pipelined as
v htjs_business_state_row_type;
businessState VARCHAR2(50);
bissid bosp_htys_businessreserve.id%type;
isquit bosp_htys_businessreserve.isquit%type;
BUS_STATE bosp_htys_businessreserve.BUS_STATE%type;
formalcensor bosp_htys_receptioninfo.formalcensor%type;
accept_state bosp_htys_receptioninfo.accept_state%type;
substanceresult bosp_htys_backstageinfo.substanceresult%type;
iscomplete bosp_htys_backstageinfo.iscomplete%type;
gather_state bosp_htys_backstageinfo.gather_state%type;
app_state bosp_htjs_contract_report.app_state%type;
back_app_state bosp_htys_backstageinfo.app_state%type;
mortem_state bosp_htys_ysinfo.mortem_state%type;
returnman bosp_htys_businessreserve.returnman%type;
issubmit bosp_htys_backstageinfo.issubmit%type;
begin
for myrow in (
--状态sql开始
SELECT
biss. ID,
biss.isquit,
biss.BUS_STATE,
rec.formalcensor,
rec.accept_state,
back.substanceresult,
back.iscomplete,
back.gather_state,
back.app_state back_app_state,
bhcreport.app_state,
ys.mortem_state,
biss.returnman,
back.issubmit
FROM
bosp_htys_businessreserve biss
LEFT JOIN bosp_htys_receptioninfo rec ON biss. ID = rec.business_id
LEFT JOIN bosp_htjs_contractinfo con ON con. ID = biss.contractinfo_id
LEFT JOIN bosp_htjs_subengineeringinfo sub ON sub. ID = con.subengineeringinfo_id
LEFT JOIN bosp_htjs_engineeringinfo eng ON eng. ID = sub.engineering_id
LEFT JOIN bosp_global_supplier sup ON con.supplier_id = sup. ID
LEFT JOIN bosp_htys_backstageinfo back ON back.qt_business_id = rec. ID
LEFT JOIN bosp_htys_budget budget ON budget.business_id = biss. ID
LEFT JOIN bosp_htys_monthlygatherinfo bhmgather ON bhmgather.business_id = biss. ID
LEFT JOIN bosp_htjs_contract_report bhcreport ON (
bhmgather.report_id = bhcreport. ID
AND bhcreport.report_type = 2
AND bhcreport.is_del = 0
)
LEFT JOIN bosp_htys_ysinfo ys ON ys.business_id = biss. ID
where biss.business_type IN (1,2,3,4,5,6)
--状态sql结束
) loop
--业务逻辑判断开始
bissid := myrow.ID;
isquit := myrow.isquit;
BUS_STATE := myrow.BUS_STATE;
formalcensor := myrow.formalcensor;
accept_state := myrow.accept_state;
substanceresult := myrow.substanceresult;
iscomplete := myrow.iscomplete;
gather_state := myrow.gather_state;
app_state := myrow.app_state;
back_app_state := myrow.back_app_state;
mortem_state := myrow.mortem_state;
returnman := myrow.returnman;
issubmit := myrow.issubmit;
dbms_output.put_line(BUS_STATE);
if BUS_STATE is not null THEN
if BUS_STATE=0 then
businessState := 'dsl';
elsif (BUS_STATE=1 or BUS_STATE=3) then
if formalcensor is null then
businessState := 'dxssc';
elsif formalcensor=0 then
businessState := 'xsscbtg';
elsif formalcensor=1 then
businessState := 'xssctg';
if accept_state=1 then
businessState := 'dszsc';
if mortem_state=4 then
businessState := 'ysth';
end if;
--实审开始
if substanceresult is not null then
if issubmit is not null then
if issubmit=1 then
if substanceresult=0 then
businessState := 'szscbtg';
elsif substanceresult=1 then
businessState := 'szsctg';
if isquit=1 then
if back_app_state is not null then
businessState := 'isquit_money_app_state' || back_app_state;
end if;
else
businessState := 'dbzys';
if iscomplete=1 then
businessState := 'ybzys';
if gather_state=1 then
if app_state is not null then
businessState := 'declare_state' || app_state;
end if;
end if;
end if;
end if;
elsif substanceresult=2 then
businessState := 'qxzz';
end if;
end if;
end if;
end if;
--实审结束
end if;
end if;
elsif BUS_STATE=2 then
businessState := 'thgys';
if formalcensor=0 then
businessState := 'xsscbtg';
end if;
end if;
end if;
--业务逻辑判断结束
v := htjs_business_state_row_type(bissid,businessState);
pipe row (v);
end loop;
return;
end;
--二:测试函数结果集表
select htjs_business_state.* from table(fun_htjs_business_state) htjs_business_state;
--三:创建对应物化视图
drop materialized view mv_htjs_business_state;
create materialized view mv_htjs_business_state refresh force on demand as select htjs_business_state.* from table(fun_htjs_business_state) htjs_business_state;
--1.查询语句:
select * from mv_htjs_business_state;
--四:调用前手动刷新物化视图
--1.pl/sql命令刷新:exec dbms_mview.refresh('mv_htjs_business_state');
--2.java中调用:call dbms_mview.refresh('mv_htjs_business_state')";
--业务状态写法二:
create or replace function fun_htjs_business_state
return htjs_business_row
as
rs htjs_business_row:= htjs_business_row();
businessState VARCHAR2(50);
bissid bosp_htys_businessreserve.id%type; isquit bosp_htys_businessreserve.isquit%type; BUS_STATE bosp_htys_businessreserve.BUS_STATE%type; formalcensor bosp_htys_receptioninfo.formalcensor%type; accept_state bosp_htys_receptioninfo.accept_state%type; substanceresult bosp_htys_backstageinfo.substanceresult%type; iscomplete bosp_htys_backstageinfo.iscomplete%type; gather_state bosp_htys_backstageinfo.gather_state%type; app_state bosp_htjs_contract_report.app_state%type; back_app_state bosp_htys_backstageinfo.app_state%type; mortem_state bosp_htys_ysinfo.mortem_state%type; returnman bosp_htys_businessreserve.returnman%type; issubmit bosp_htys_backstageinfo.issubmit%type; begin for myrow in( --状态sql开始 SELECT biss. ID,biss.isquit,biss.BUS_STATE,rec.formalcensor,rec.accept_state,back.substanceresult,back.iscomplete,back.gather_state,back.app_state back_app_state,bhcreport.app_state,ys.mortem_state,biss.returnman,back.issubmit FROM bosp_htys_businessreserve biss LEFT JOIN bosp_htys_receptioninfo rec ON biss. ID = rec.business_id LEFT JOIN bosp_htjs_contractinfo con ON con. ID = biss.contractinfo_id LEFT JOIN bosp_htjs_subengineeringinfo sub ON sub. ID = con.subengineeringinfo_id LEFT JOIN bosp_htjs_engineeringinfo eng ON eng. ID = sub.engineering_id LEFT JOIN bosp_global_supplier sup ON con.supplier_id = sup. ID LEFT JOIN bosp_htys_backstageinfo back ON back.qt_business_id = rec. ID LEFT JOIN bosp_htys_budget budget ON budget.business_id = biss. ID LEFT JOIN bosp_htys_monthlygatherinfo bhmgather ON bhmgather.business_id = biss. ID LEFT JOIN bosp_htjs_contract_report bhcreport ON ( bhmgather.report_id = bhcreport. ID AND bhcreport.report_type = 2 AND bhcreport.is_del = 0 ) LEFT JOIN bosp_htys_ysinfo ys ON ys.business_id = biss. ID where biss.business_type IN (1,6) --状态sql结束 ) loop --业务逻辑判断开始 bissid := myrow.ID; isquit := myrow.isquit; BUS_STATE := myrow.BUS_STATE; formalcensor := myrow.formalcensor; accept_state := myrow.accept_state; substanceresult := myrow.substanceresult; iscomplete := myrow.iscomplete; gather_state := myrow.gather_state; app_state := myrow.app_state; back_app_state := myrow.back_app_state; mortem_state := myrow.mortem_state; returnman := myrow.returnman; issubmit := myrow.issubmit; dbms_output.put_line(BUS_STATE); if BUS_STATE is not null THEN if BUS_STATE=0 then businessState := 'dsl'; elsif (BUS_STATE=1 or BUS_STATE=3) then if formalcensor is null then businessState := 'dxssc'; elsif formalcensor=0 then businessState := 'xsscbtg'; elsif formalcensor=1 then businessState := 'xssctg'; if accept_state=1 then businessState := 'dszsc'; if mortem_state=4 then businessState := 'ysth'; end if; --实审开始 if substanceresult is not null then if issubmit is not null then if issubmit=1 then if substanceresult=0 then businessState := 'szscbtg'; elsif substanceresult=1 then businessState := 'szsctg'; if isquit=1 then if back_app_state is not null then businessState := 'isquit_money_app_state' || back_app_state; end if; else businessState := 'dbzys'; if iscomplete=1 then businessState := 'ybzys'; if gather_state=1 then if app_state is not null then businessState := 'declare_state' || app_state; end if; end if; end if; end if; elsif substanceresult=2 then businessState := 'qxzz'; end if; end if; end if; end if; --实审结束 end if; end if; elsif BUS_STATE=2 then businessState := 'thgys'; if formalcensor=0 then businessState := 'xsscbtg'; end if; end if; end if; --增加记录 rs.extend; DBMS_OUTPUT.put_line (rs.count); rs(rs.count) := htjs_business_state_row_type(bissid,businessState); end loop; return rs; end fun_htjs_business_state;
总结
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
oracle返回表id,Oracle 函数返回表实例2种写法实例相关推荐
- 模板引擎不关心内容之——art-template,碰见的同步与fs.readFile异步以及函数回调问题的描述,针对fs的readfille读取文件时,返回不了异步函数返回值的解决方法
模板引擎不关心内容 art-template art-template不仅可以在浏览器使用,也可以在node中使用 npm install art-template该命令在哪执行就会把包下载在哪里,默 ...
- pandas使用groupby函数和count函数返回的是分组下每一列的统计值(不统计NaN缺失值)、如果多于一列返回dataframe、size函数返回分组下的行数结果为Series(缺失值不敏感)
pandas使用groupby函数和count函数返回的是分组下每一列的统计值(不统计NaN缺失值).如果多于一列返回dataframe.size函数返回分组下的行数结果为Series(不区分缺失值和 ...
- “正话反说”:A和B在玩一个游戏,两人轮流说一句话,这句话正读反读都一样,如adgda,谁先说错,谁出局,另一个人胜出。编写一个函数用于判断这句话是否符合要求,符合要求时,函数返回1,否则函数返回0
"正话反说":A和B在玩一个游戏,两人轮流说一句话,这句话正读反读都一样,如adgda,谁先说错,谁出局,另一个人胜出. 编写一个函数用于判断这句话是否符合要求,符合要求时,函数返 ...
- c语言自定义函数多个返回值,C语言函数返回值
C语言函数返回值教程 如果,我们希望函数不返回任何值,那么我们需要显式的指明其返回类型为 C语言函数不返回值 语法 void funcName(paramType1 param1, paramType ...
- 按主键更新另一个表oracle,SQL根据ID匹配从一个表更新到另一个表
我相信一个连接的UPDATE FROM将有助于: MS SQL UPDATE Sales_Import SET Sales_Import.AccountNumber = RAN.AccountNumb ...
- Shell函数(函数定义、函数变量、函数调用、函数传参、函数返回值、获取函数返回值)
分享知识 传递快乐 1.函数定义 linux shell 可以用户定义函数,然后在shell脚本中可以随便调用.Shell 函数定义的语法格式如下: [function] funname [()]{函 ...
- python函数能返回列表吗_Python函数返回列表还是作为生成器工作?
我正在尝试创建一个返回对象或作为生成器的函数. 这是一个坏主意,因为作为一种最佳实践,您希望函数可靠地返回相同类型的值,但为了科学的利益-- 我正在使用Python 2,因此range返回一个列表,x ...
- 存储过程返回结果集_PostgreSQL函数返回结果集
有时我们需要定义返回结果集的函数,本文演示如何编码. 遂古之初,谁传道之?上下未形,何由考之?<天问> 1.函数定义 C语言定义部分 PG_FUNCTION_INFO_V1(quanzl_ ...
- c语言怎么返回数组,c++从函数返回数组的方法代码
c++如何从函数返回数组? C++ 从函数返回数组 C++ 不允许返回一个完整的数组作为函数的参数.但是,您可以通过指定不带索引的数组名来返回一个指向数组的指针. 如果您想要从函数返回一个一维数组,您 ...
最新文章
- 使用Python和OpenCV检测图像中的条形码
- 通道Channel-使用NIO 写入数据
- c++调用Libsvm
- Python精通-Python字典操作
- 各种排序算法稳定性的总结!!!
- 【特色团队采访】1+1+1>3?看新人团队如何高效合作
- 演示:思科交换机的Telnet管理与SSH管理
- 原型对象prototype与继承
- 钉钉 e应用 mysql_钉钉E应用入门总结
- UniBeast:在任何支持基于英特尔处理器的PC上安装OS X优胜美地
- 【C语言】实现网络对战五子棋
- VIEW: X$KSMLRU - LRU flushes from the shared pool - (7.3 - 8.1) [ID 43600.1]
- 百度公司关于SEO的建议
- 多线程应用_左圆右方
- 【Windows必备软件】01 Groupy 实现你所有的窗口标签化管理
- getchar消除回车符号
- foxmail7.2导入地址簿
- 程序员转行为什么这么难--[转]
- 基于S32K144 CAN总线功能开发详解
- Whale帷幄 - 企业数字化解决方案服务商 数字化方案提供商