DECLARE
-- 修正用プログラム
DECLARE
CURSOR c_adv_fee_detail IS
SELECT adv_fee.fee_mgmt_num,
adv_fee.fee_mgmt_eda,
adv_fee.receipt_num,
adv_fee.his,
adv_fee.ksai_sha_code,
adv_fee.teisei_kubun,
adv_fee.adv_baitai_bunrui_code,
adv_fee.moko_kind,
adv_fee.adv_kind_mcode,
adv_fee.adv_sha_name,
adv_fee.dan_kansan_space,
adv_fee.gross_fee,
adv_fee.input_per_code
FROM tb_adv_fee_detail adv_fee
WHERE
--料金情報(基本)に存在する(料金管理番号、枝番で結合する)
EXISTS (SELECT 1
FROM tb_fee_info_basic fee
WHERE fee.fee_mgmt_num = adv_fee.fee_mgmt_num
AND fee.fee_mgmt_eda =
'0' || substr(adv_fee.fee_mgmt_eda, 2, 2))
--受付番号、履歴番号と掲載者の条件を追加して、料金情報(基本)に存在しない
AND NOT EXISTS (SELECT 1
FROM tb_fee_info_basic fee
WHERE fee.receipt_num = adv_fee.receipt_num
AND fee.his = adv_fee.his
AND fee.ksai_sha_code = adv_fee.ksai_sha_code
AND fee.fee_mgmt_num = adv_fee.fee_mgmt_num
AND fee.fee_mgmt_eda =
'0' || substr(adv_fee.fee_mgmt_eda, 2, 2))
AND adv_fee.input_per_code = 'IKOU'
/* AND adv_fee.receipt_num = 'W12022000286'
AND adv_fee.his = '002'
AND adv_fee.ksai_sha_code = '1'*/
;
vReceiptNum tb_adv_fee_detail.receipt_num%TYPE;
vHis tb_adv_fee_detail.his%TYPE;
CURSOR c_tafd_1 IS
SELECT *
FROM (SELECT tafd.receipt_num,
tafd.his,
tafd.ksai_sha_code,
tafd.dan_kansan_space,
row_number() over(PARTITION BY tafd.receipt_num, tafd.his, tafd.ksai_sha_code ORDER BY tafd.fee_mgmt_num DESC, tafd.fee_mgmt_eda DESC) rn
FROM tb_adv_fee_detail tafd
WHERE tafd.adv_kind_mcode = '1' --記事下
AND tafd.dan_kansan_space <> 0 --段換算スペース
AND tafd.moko_kind NOT IN ('12', '19') --フリー、仮版
AND tafd.teisei_kubun IN ('2', '3') --黒、訂正なし
AND tafd.input_per_code = 'IKOU'
AND NOT EXISTS
(SELECT 1
FROM tb_tokei_dansu_kanri dan
WHERE dan.receipt_num = tafd.receipt_num
AND dan.his = tafd.his
AND dan.ksai_sha_code = tafd.ksai_sha_code
AND dan.fee_mgmt_num = '************'
AND dan.fee_mgmt_eda = '***'))
WHERE rn = 1;
CURSOR c_tafd_2 IS
SELECT tafd.receipt_num,
tafd.his,
tafd.ksai_sha_code,
tafd.fee_mgmt_num,
tafd.fee_mgmt_eda,
tafd.dan_kansan_space
FROM tb_adv_fee_detail tafd
WHERE ((tafd.adv_kind_mcode = '1' AND tafd.dan_kansan_space <> 0 AND
tafd.moko_kind NOT IN ('12', '19')) OR
(tafd.adv_kind_mcode = '2' AND tafd.dan_kansan_space <> 0))
AND tafd.input_per_code = 'IKOU'
AND NOT EXISTS
(SELECT 1
FROM tb_tokei_dansu_kanri dan
WHERE dan.receipt_num = tafd.receipt_num
AND dan.his = tafd.his
AND dan.ksai_sha_code = tafd.ksai_sha_code
AND dan.fee_mgmt_num = tafd.fee_mgmt_num
AND dan.fee_mgmt_eda = tafd.fee_mgmt_eda);
vErrKey VARCHAR2(1024);
BEGIN
DELETE FROM tb_tokei_dansu_kanri dan
WHERE EXISTS
(SELECT 1
FROM tb_adv_fee_detail adv_fee
WHERE
--料金情報(基本)に存在する(料金管理番号、枝番で結合する)
EXISTS (SELECT 1
FROM tb_fee_info_basic fee
WHERE fee.fee_mgmt_num = adv_fee.fee_mgmt_num
AND fee.fee_mgmt_eda =
'0' || substr(adv_fee.fee_mgmt_eda, 2, 2))
--受付番号、履歴番号と掲載者の条件を追加して、料金情報(基本)に存在しない
AND NOT EXISTS (SELECT 1
FROM tb_fee_info_basic fee
WHERE fee.receipt_num = adv_fee.receipt_num
AND fee.his = adv_fee.his
AND fee.ksai_sha_code = adv_fee.ksai_sha_code
AND fee.fee_mgmt_num = adv_fee.fee_mgmt_num
AND fee.fee_mgmt_eda =
'0' || substr(adv_fee.fee_mgmt_eda, 2, 2))
AND dan.receipt_num = adv_fee.receipt_num
AND dan.his = adv_fee.his
AND dan.ksai_sha_code = adv_fee.ksai_sha_code
AND ((dan.fee_mgmt_num = '************' AND
dan.fee_mgmt_eda = '***') OR
(dan.fee_mgmt_num = adv_fee.fee_mgmt_num AND
dan.fee_mgmt_eda = adv_fee.fee_mgmt_eda))
/* AND adv_fee.receipt_num = 'W12022000286'
AND adv_fee.his = '002'
AND adv_fee.ksai_sha_code = '1'*/
);
FOR c_row IN c_adv_fee_detail
LOOP
BEGIN
vErrKey := c_row.receipt_num || '-' || c_row.his || '-' ||
c_row.ksai_sha_code || '-' || c_row.fee_mgmt_num || '-' ||
c_row.fee_mgmt_eda;
-- 料金情報基本から受付番号と履歴番号を取得
SELECT receipt_num,
his
INTO vReceiptNum,
vHis
FROM tb_fee_info_basic
WHERE fee_mgmt_num = c_row.fee_mgmt_num
AND fee_mgmt_eda = '0' || substr(c_row.fee_mgmt_eda, 2, 2);
-- 広告料金明細を更新
UPDATE tb_adv_fee_detail
SET receipt_num = vReceiptNum,
his = vHis,
update_date_time = SYSDATE,
update_per_code = 'M0013510'
WHERE fee_mgmt_num = c_row.fee_mgmt_num
AND fee_mgmt_eda = c_row.fee_mgmt_eda;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('1:' || vErrKey || ':' ||
SQLERRM(SQLCODE));
END;
END LOOP;
FOR c_row1 IN c_tafd_1
LOOP
BEGIN
vErrKey := c_row1.receipt_num || '-' || c_row1.his || '-' ||
c_row1.ksai_sha_code || '-' || '************' || '-' ||
'***';
INSERT /*+APPEND*/
INTO tb_tokei_dansu_kanri
(receipt_num,
his,
ksai_sha_code,
fee_mgmt_num,
fee_mgmt_eda,
tokei_dansu,
input_date_time,
input_per_code,
update_date_time,
update_per_code,
update_count,
del_flg,
del_date_time,
del_per_code)
VALUES
(c_row1.receipt_num,
c_row1.his,
c_row1.ksai_sha_code,
'************',
'***',
c_row1.dan_kansan_space,
SYSDATE,
'IKOU',
SYSDATE,
'M0013510',
0,
'0',
NULL,
NULL);
UPDATE tb_moko_info_ksai_sha_betsu
SET tokei_dansu = c_row1.dan_kansan_space
WHERE receipt_num = c_row1.receipt_num
AND his = c_row1.his
AND ksai_sha_code = c_row1.ksai_sha_code;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('2:' || vErrKey || ':' ||
SQLERRM(SQLCODE));
END;
END LOOP;
FOR c_row2 IN c_tafd_2
LOOP
BEGIN
vErrKey := c_row2.receipt_num || '-' || c_row2.his || '-' ||
c_row2.ksai_sha_code || '-' || c_row2.fee_mgmt_num || '-' ||
c_row2.fee_mgmt_eda;
INSERT /*+APPEND*/
INTO tb_tokei_dansu_kanri
(receipt_num,
his,
ksai_sha_code,
fee_mgmt_num,
fee_mgmt_eda,
tokei_dansu,
input_date_time,
input_per_code,
update_date_time,
update_per_code,
update_count,
del_flg,
del_date_time,
del_per_code)
VALUES
(c_row2.receipt_num,
c_row2.his,
c_row2.ksai_sha_code,
c_row2.fee_mgmt_num,
c_row2.fee_mgmt_eda,
c_row2.dan_kansan_space,
SYSDATE,
'IKOU',
SYSDATE,
'M0013510',
0,
'0',
NULL,
NULL);
UPDATE tb_moko_info_ksai_sha_betsu
SET tokei_dansu = c_row2.dan_kansan_space
WHERE receipt_num = c_row2.receipt_num
AND his = c_row2.his
AND ksai_sha_code = c_row2.ksai_sha_code;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('3:' || vErrKey || ':' ||
SQLERRM(SQLCODE));
END;
END LOOP;
END;
DECLARE的更多相关文章
- mysql substring函数截取值后赋给一个declare变量
今天写的一个mysql存储过程涉及到对一个传入参数的字符串截取,然后需要判断截取字符串进行一系列操作,最开始用select subtring() into 这样的方法将截取值赋于declare变量直 ...
- 关于Django 错误 doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS
记录一下 报错 doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS\ 这个问题出现没 ...
- rabbitmq method之queue.declare
queue.declare即申请队列,首先对队列名作处理,若未指定队列名则随机生成一个,然后查询数据库队列是否已经创建,若创建完成则会申请队列返回 handle_method(#'queue.decl ...
- LINUX:read、array、declare
read:要读取来自键盘输入的变量 使用规则: read [-pt] variale 选项与参数: -p:后面接提示字符: -t:后面接等待的“秒数”: 如果read之后不加任何参数,直接加上变量名称 ...
- Ubuntu 下使用declare的问题
Ubuntu在shell的执行上用户root和普通用户是不一样的. 使用vi /etc/passwd 我们就可以看到在用户的最后一行也就是定义shell执行位置的地方root的位置是/bin/bash ...
- dojo分析之declare接口
欢迎转载opendevkit文章, 文章原始地址: http://www.opendevkit.com/?e=57 declare接口是dojo定义类系统的关键函数, 类系统就是抽象,封装,继承.do ...
- 关于The serializable class XXX does not declare a static final serialVersionUID field of type long的警告
编写实体类并且继承序列化接口时候,实体类会有警告,要生成一个静态的serialVersionUID. 上网搜了一下资料,现通俗解释一下: 点击前2个选项,会生成: private static fin ...
- PHP declare(ticks=N); 的作用
一般用法是 declare(ticks=N);拿declare(ticks=1)来说,这句主要作用有两种: 1.Zend引擎每执行1条低级语句就去执行一次 register_tick_function ...
- (转)create table #temptable 临时表 和 declare @bianliang table ()表变量
在开发过程中,经常会遇到使用表变量和本地临时表的情况.下面是对二者的一个介绍: 1. 为什么要使用表变量 表变量是从2000开始引入的,微软认为与本地临时表相比,表变量具有如下优点: a.与其他变量 ...
- 有时候为了方便sql语句的对比和查询,我们可以使用declare来定义变量 上下篇的问题
--定义一些参数 declare @nodeId int,@ekid int ,@ecid int,@eid int,@pid int --列表 SELECT * FROM ( SELECT *,RO ...
随机推荐
- windows 环境下搭建docker私有仓库
windows 环境下搭建docker私有仓库 1.在公用仓库中pull仓库镜像 docker pull regitry 2.启动仓库镜像 //-d意思是后台运行,-p是做端口映射,这里是将本地的50 ...
- idea中查看方法的调用链
Eclipse的"Call Hierarchy"可以查看一个Java方法或类成员变量的调用树(caller和callee两个方向),非常方便. 在IDEA中类似功能被划分到了三个 ...
- python OneHot编码
- JS 获取浏览器窗口大小 获取屏幕,浏览器,网页高度宽度
网页可见区域宽:document.body.clientWidth 网页可见区域高:document.body.clientHeight 网页可见区域宽:document.body.offsetWid ...
- mybatis官网文档mybatis_doc
在平时的学习中,我们可以去参考官网的文档来学习,这个文档有中文的,方便我们去阅读,而且这里的分类很详细. 官网文档链接:http://www.mybatis.org/mybatis-3/zh/inde ...
- QT_string转char*
char* convertQString2char(const QString &str) { QByteArray ba = str.toUtf8(); char * pathChar = ...
- Android学习笔记之mainfest文件中android属性
android:allowTaskReparenting 是否允许activity更换从属的任务,比如从短信息任务 切换到浏览器任务. -------------------------------- ...
- AndroidStudio离线打包MUI集成JPush极光推送并在java后端管理推送
1.AndroidStudio离线打包MUI 如何离线打包请参看上篇随笔<AndroidStudio离线打包MUI> 2.集成极光推送 官方文档:https://docs.jiguang. ...
- 如何在不卸载原来jdk1.8的情况下切换到jdk1.7
将Path环境变量中的JAVA_HOME变量中写入现在的JDK1.7路径即可.
- day38 15-Spring的配置文件引入的问题
配置文件内容过多修改起来维护起来很麻烦.Struts 2可以在总的配置文件中引入其他的配置文件.这是一种办法.第二种办法在加载配置文件的时候,里面可以一次性传多个. <?xml version= ...