oracle - 带有游标的过程,以便使用视图增量填充表
问题描述
看法:
po po_line month year amount
41216 10 jan 2018 3000
41216 20 feb 2018 4000
41216 30 Aug 2018 6000
54321 10 march 2018 7000
32133 10 feb 2018 5000
桌子:
po po_line month year amount
41216 10 jan 2018 3000
41216 20 feb 2018 4000
我需要一个带有游标的过程,以便使用视图增量填充表。
这个想法是,当视图被更新时,更新的数据应该被插入到表中。
代码:
create or replace procedure prc as
cursor c1 is
select *
from vw_po_tab
where po||po_line not in(select po||po_line from po_tab1);
begin
for i in c1 loop
insert into po_tab1(po,po_line,month,year, amount)
values(i.po,i.po_line,i.month,i.year, i.amount);
end loop;
end;
解决方案
您不需要循环(甚至不需要过程)。您可以使用一个 INSERT 语句来做到这一点:
insert into po_tab1(po,po_line,month,year, amount)
select po, po_line, month, year, amount
from vw_po_tab
where (po, po_line) not in (select po, po_line
from po_tab1);
对于多列IN
条件,您不应连接两个值,而应使用两个单独的列。因为如果你将它们连接起来1,12
,并且11,2
将是相同的。
推荐阅读
- numpy - 向量化 numpy 代码
- python - 要求用户选择文件夹以读取 Python 中的文件?
- java - Java Postgresql 驱动程序是否支持数组数据类型,得到 NullPointerException
- python - NLTK word Lemmatizer 奇怪的行为 - POS 标记的帮助 - Python 3
- android - 错误配置“编译”已过时,已替换为“实现”和 api
- extjs - 如何在散点图中使用监听器获取getLimit()和setLimit()方法?
- python - 如何使用训练有素的skipgram模型预测单词?
- c++ - 使用 C++ 标准库避免共享库中的符号冲突
- javascript - Plot.ly 在传递跟踪数组时不呈现
- java - 何时在 sqlite 中打开和关闭与数据库的连接?