CREATE OR REPLACE PROCEDURE data_transplant(objType in NUMBER,
startTime in varchar2,
endTime in varchar2,
ids in varchar2
--,
--title in varchar2,
--sectionId in varchar2
)
------------ 移植业务表到历史表 by iehyou -----------
--有2种执行方式:
--1.移植执行ID (参数:ids)的Ojbect表和子表数据到历史表);
--2.根据类别和时间(参数:objType,startTime,endTime)查询的数据移植;
------------ 移植业务表到历史表 by iehyou -----------
AUTHID CURRENT_USER
is
execSql varchar2(1000);
type c_obj_ref is ref cursor;
c_obj c_obj_ref;
obj ITV_OBJECT%rowtype;
begin
DBMS_OUTPUT.PUT_LINE('objType:' || objType);
DBMS_OUTPUT.PUT_LINE('startTime:' || startTime);
DBMS_OUTPUT.PUT_LINE('endTime:' || endTime);
--拼接执行sql;
execSql := ' FROM itv.ITV_OBJECT obj22 where 1=1 ';
if (length(ids) > 0) then
begin
execSql := execSql || ' and obj22.object_id in (' || ids || ')';
end;
else
begin
if (objType> 0) then
begin
execSql := execSql || ' and obj22.type_id = ' ||objType ;
end;
end if;
execSql := execSql||' AND to_char(obj22.online_time, ''yyyy-MM-dd hh24:mm:ss'') >='''||startTime||''''
||' AND to_char(obj22.online_time, ''yyyy-MM-dd hh24:mm:ss'') <= '''||endTime||'''';
end;
end if;
--DBMS_OUTPUT.PUT_LINE('title:'||title);
--DBMS_OUTPUT.PUT_LINE('sectionId:'||sectionId);
--保存 itv.ITV_HIS_OBJECT
-- DBMS_OUTPUT.PUT_LINE('INSERT INTO itv.ITV_HIS_OBJECT (SELECT * '
-- ||execSql || ')');
execute immediate ('INSERT INTO itv.ITV_HIS_OBJECT (SELECT * ' ||
execSql || ')');
--打开游标
DBMS_OUTPUT.PUT_LINE('select * ' || execSql);
OPEN c_obj for('select * ' || execSql);
LOOP
FETCH c_obj
INTO obj;
EXIT WHEN c_obj%NOTFOUND;
if (obj.type_id = 1) then
begin
--保存 itv.ITV_His_Vote
INSERT INTO itv.ITV_His_Vote
SELECT *
FROM itv.ITV_vote vote
WHERE exists (select h_obj.object_id
from itv.ITV_HIS_OBJECT h_obj
where h_obj.object_id = vote.vote_id
and h_obj.object_id = obj.object_id);
--保存 itv.ITV_His_Vote_Opt
INSERT INTO itv.ITV_His_Vote_Opt
SELECT *
FROM itv.ITV_vote_opt v_opt
WHERE exists (select h_vote.vote_id
from itv.ITV_His_Vote h_vote
where h_vote.vote_id = v_opt.vote_id
and h_vote.vote_id = obj.object_id);
--保存 itv.ITV_His_Vote_rst
INSERT INTO itv.ITV_His_Vote_rst
SELECT *
FROM itv.ITV_vote_rst v_rst
WHERE exists (select h_v_opt.opt_id
from itv.ITV_His_Vote_opt h_v_opt
where h_v_opt.vote_id = obj.object_id
and h_v_opt.opt_id = v_rst.opt_id);
--删除 itv.ITV_vote_rst
delete FROM itv.ITV_vote_rst t3
WHERE exists (select t3.opt_id
from itv.ITV_Vote_opt d_h_v_opt
where d_h_v_opt.vote_id = obj.object_id
and d_h_v_opt.opt_id = t3.opt_id);
--删除 itv.ITV_vote_opt
delete from itv.ITV_vote_opt t2 where t2.vote_id = obj.object_id;
--删除 itv.ITV_vote
delete from itv.ITV_vote t1 where t1.vote_id = obj.object_id;
end;
--竞猜
elsif (obj.type_id = 2) then
begin
--保存 itv.ITV_His_Guss
INSERT INTO itv.ITV_His_Guss
SELECT *
FROM itv.ITV_guss guss
WHERE exists (select h_obj.object_id
from itv.ITV_HIS_OBJECT h_obj
where h_obj.object_id = guss.guss_id
and h_obj.object_id = obj.object_id);
--保存 itv.ITV_His_Guss_Opt
INSERT INTO itv.ITV_His_Guss_Opt
SELECT *
FROM itv.ITV_guss_opt g_opt
WHERE exists (select h_guss.guss_id
from itv.ITV_His_guss h_guss
where h_guss.guss_id = g_opt.guss_id
and h_guss.guss_id = obj.object_id);
--保存 itv.ITV_His_guss_rst
INSERT INTO itv.ITV_His_guss_rst
SELECT *
FROM itv.ITV_guss_rst g_rst
WHERE exists (select h_g_opt.opt_id
from itv.ITV_His_guss_opt h_g_opt
where h_g_opt.guss_id = obj.object_id
and h_g_opt.opt_id = g_rst.opt_id);
--保存 itv.ITV_His_guss_asw
INSERT INTO itv.ITV_His_guss_asw
SELECT *
FROM itv.ITV_guss_asw g_asw
WHERE exists (select h_g_opt.opt_id
from itv.ITV_His_Guss_Opt h_g_opt
where h_g_opt.guss_id = obj.object_id
and h_g_opt.opt_id = g_asw.opt_id);
--删除 itv.ITV_guss_asw
delete FROM itv.ITV_guss_asw g4
WHERE exists (select d_h_g_opt.opt_id
from itv.ITV_guss_opt d_h_g_opt
where d_h_g_opt.guss_id = obj.object_id
and d_h_g_opt.opt_id = g4.opt_id);
--删除 itv.ITV_guss_rst
delete FROM itv.ITV_guss_rst g3
WHERE exists (select d_h_g_opt.opt_id
from itv.ITV_guss_opt d_h_g_opt
where d_h_g_opt.guss_id = obj.object_id
and d_h_g_opt.opt_id = g3.opt_id);
--删除 itv.ITV_guss_opt
delete from itv.ITV_guss_opt g2 where g2.guss_id = obj.object_id;
--删除 itv.ITV_guss
delete from itv.ITV_guss g1 where g1.guss_id = obj.object_id;
end;
-- 讨论
elsif (obj.type_id = 3) then
begin
--保存 itv.ITV_His_dscs
INSERT INTO itv.ITV_His_dscs
SELECT *
FROM itv.ITV_dscs dscs
WHERE exists (select h_obj.object_id
from itv.ITV_HIS_OBJECT h_obj
where h_obj.object_id = dscs.dscs_id
and h_obj.object_id = obj.object_id);
--保存 itv.ITV_His_dscs_rst
INSERT INTO itv.ITV_His_dscs_rst
SELECT *
FROM itv.ITV_dscs_rst g_rst
WHERE exists (select h_dscs.dscs_id
from itv.ITV_His_dscs h_dscs
where h_dscs.dscs_id = g_rst.dscs_id
and h_dscs.dscs_id = obj.object_id);
--保存 itv.ITV_HIS_DSCS_PHRASE
INSERT INTO itv.ITV_HIS_DSCS_PHRASE
SELECT *
FROM itv.ITV_DSCS_PHRASE d_ph
WHERE exists (select h_dscs.dscs_id
from itv.ITV_His_dscs h_dscs
where h_dscs.dscs_id = d_ph.dscs_id
and h_dscs.dscs_id = obj.object_id);
--删除 itv.ITV_DSCS_PHRASE
delete from itv.ITV_DSCS_PHRASE d3 where d3.dscs_id = obj.object_id;
--删除 itv.ITV_dscs_rst
delete from itv.ITV_dscs_rst d2 where d2.dscs_id = obj.object_id;
--删除 itv.ITV_guss
delete from itv.ITV_dscs d1 where d1.dscs_id = obj.object_id;
end;
--收视
elsif (obj.type_id = 4) then
begin
--保存 itv.ITV_HIS_AUDIENCE
INSERT INTO itv.ITV_HIS_AUDIENCE
SELECT *
FROM itv.ITV_AUDIENCE au
WHERE exists (select h_obj.object_id
from itv.ITV_HIS_OBJECT h_obj
where h_obj.object_id = au.audience_id
and h_obj.object_id = obj.object_id);
--保存 itv.ITV_HIS_AUDIENCE_PERSON
INSERT INTO itv.ITV_HIS_AUDIENCE_PERSON
SELECT *
FROM itv.ITV_AUDIENCE_PERSON a_per
WHERE exists (select h_au.audience_id
from itv.ITV_His_Audience h_au
where h_au.audience_id = a_per.audience_id
and h_au.audience_id = obj.object_id);
--保存 itv.ITV_his_audience_show_time
INSERT INTO itv.ITV_his_audience_show_time
SELECT *
FROM itv.ITV_audience_show_time a_time
WHERE exists (select h_au.audience_id
from itv.ITV_His_Audience h_au
where h_au.audience_id = a_time.audience_id
and h_au.audience_id = obj.object_id);
--删除 itv.ITV_audience_show_time
delete from itv.ITV_audience_show_time a3
where a3.audience_id = obj.object_id;
--删除 itv.ITV_AUDIENCE_PERSON
delete from itv.ITV_AUDIENCE_PERSON a2
where a2.audience_id = obj.object_id;
--删除 itv.ITV_AUDIENCE
delete from itv.ITV_AUDIENCE a1 where a1.audience_id = obj.object_id;
end;
elsif (obj.type_id = 5) then
begin
--内容
--保存 itv.ITV_HIS_CONTENT
INSERT INTO itv.ITV_HIS_CONTENT
SELECT *
FROM itv.ITV_HIS_CONTENT h_con
WHERE exists (select h_obj.object_id
from itv.ITV_HIS_OBJECT h_obj
where h_obj.object_id = h_con.content_id
and h_obj.object_id = obj.object_id);
--删除 itv.ITV_AUDIENCE
delete from itv.ITV_CONTENT c1 where c1.content_id = obj.object_id;
end;
end if;
END LOOP;
CLOSE c_obj;
--删除 itv.ITV_OBJECT
DBMS_OUTPUT.PUT_LINE(' delete ' || execSql);
execute immediate (' delete ' || execSql);
COMMIT;
end;
分享到:
相关推荐
本文将从 Oracle 存储过程的基础知识开始,逐步深入到 Oracle 存储过程的高级应用,包括 Hibernate 调用 Oracle 存储过程和 Java 调用 Oracle 存储过程的方法。 Oracle 存储过程基础知识 Oracle 存储过程是 Oracle...
Oracle存储过程unwrap解密工具主要用于处理Oracle数据库中的加密存储过程。在Oracle数据库系统中,为了保护敏感代码或数据,开发人员有时会选择对存储过程进行加密。然而,当需要查看、调试或恢复这些加密的存储过程...
总结起来,"帆软报表Oracle存储过程解决storeParameter1参数试用插件"主要是针对在调用无参数Oracle存储过程时出现的异常问题提供的一种解决方案。通过安装并配置这个插件,用户可以顺利地在帆软报表中调用不包含...
以下是对“oracle存储过程解锁”这一主题的深入解析。 ### 标题:“oracle存储过程解锁” #### 解析: 在Oracle数据库中,存储过程是一种预先编译并存储在数据库中的SQL代码块,用于执行复杂的业务逻辑或数据处理...
本文实例讲述了Python使用cx_Oracle调用Oracle存储过程的方法。分享给大家供大家参考,具体如下: 这里主要测试在Python中通过cx_Oracle调用PL/SQL。 首先,在数据库端创建简单的存储过程。 create or replace ...
在Oracle存储过程中,`IN`参数用于传递数据到过程,`OUT`参数则允许过程向调用者返回数据。而`SYS_REFCURSOR`是Oracle提供的一种特殊类型,它允许存储过程动态地打开一个游标(即结果集)并将其作为`OUT`参数返回。 ...
Oracle存储过程是数据库管理系统中的一种重要特性,它允许开发者编写一系列SQL语句和PL/SQL块,形成可重复使用的代码单元。这篇博客“oracle存储过程-帮助文档”可能提供了关于如何创建、调用和管理Oracle存储过程...
### Oracle存储过程、函数与DBLink详解 #### 一、Oracle存储过程简介 在Oracle数据库中,存储过程是一种预编译好的SQL代码集合,它可以接受输入参数、返回单个值或多个值,并能够执行复杂的数据库操作。存储过程...
oracle 存储过程导出excel oracle 存储过程导出excel oracle 存储过程导出excel oracle 存储过程导出excel oracle 存储过程导出excel
以下是一个简单的示例,展示了如何调用一个不带参数的Oracle存储过程: ```java Session session = sessionFactory.openSession(); Transaction transaction = session.beginTransaction(); session....
本文将详细讲解如何在C#中使用自定义列表(List)作为参数调用Oracle存储过程,以及实现这一功能的关键技术和注意事项。 首先,我们需要了解Oracle数据库中的PL/SQL类型,例如VARCAR2、NUMBER等,它们对应于C#中的...
本文将深入探讨如何在Spring Boot项目中整合MyBatis,实现调用Oracle存储过程并处理游标返回的数据。 首先,我们需要在Spring Boot项目中引入相关的依赖。在`pom.xml`文件中添加Oracle JDBC驱动(ojdbc66-oracle...
Oracle存储过程是数据库管理系统Oracle中的一个关键特性,它允许开发者编写一组预编译的SQL和PL/SQL语句,以实现特定的业务逻辑或数据库操作。这篇教程将深入讲解Oracle存储过程的各个方面,帮助你从基础到高级全面...
### Oracle存储过程批量提交知识点详解 在Oracle数据库中,存储过程是一种重要的数据库对象,它可以包含一系列SQL语句和控制流语句,用于实现复杂的业务逻辑处理。存储过程不仅可以提高应用程序性能,还可以确保...
本篇文章将深入探讨如何在Oracle存储过程中使用临时表,包括会话级临时表和事务级临时表。 ### 会话级临时表 会话级临时表(Session-Level Temporary Tables)只在创建它的会话内可见,并且在会话结束时自动删除。...
Oracle存储过程常用技巧 Oracle存储过程是一种强大的数据库对象,它可以帮助开发者简化复杂的业务逻辑,并提高数据库的安全性和性能。在 Oracle 中,存储过程是一种特殊的 PL/SQL 程序,它可以接受输入参数,执行...
标题中的“pb中执行oracle存储过程脚本”指的是在PowerBuilder(简称PB)环境中调用Oracle数据库的存储过程。PowerBuilder是一种可视化的开发工具,常用于构建数据驱动的应用程序。Oracle存储过程则是在Oracle数据库...
可以将SQL Server存储过程转为oracle存储过程的工具
Oracle 存储过程调用 CallabledStatement 实用例子(IN OUT 传游标) 一、Oracle 存储过程简介 Oracle 存储过程是一种可以在 Oracle 数据库中存储和执行的程序单元。存储过程可以由多种语言编写,例如 PL/SQL、...
本话题将详细探讨如何在Oracle存储过程中调用外部的批处理脚本,如Windows系统的BAT文件,以实现数据库操作与系统命令的集成。 首先,`Oracle存储过程`是一种预编译的SQL和PL/SQL代码集合,可以被多次调用以执行...