sql - 如何将逐行值更新到表 pl/sql
问题描述
在 pl/sql 块中的一些操作之后,我在将值更新到表中时遇到问题,但我不知道如何将这些值放回 SQL 表中。
我猜不需要声明块,但我会抛出我使用的所有代码
t_procent:=t_ud_c/c_faktura;
我想在 FOR 循环中将交易表的上限值逐行放入“procent_alokacji”列中,但我不知道为什么我不能这样做。怎么做?
Declare
type table_products is table of products.unit_duration_calculation%type;
t_products table_products:= table_products();
type table_clients is table of clients.faktura_suma_cj%type;
t_clients table_clients:= table_clients();
CURSOR c_clients is
Select id_c, faktura_suma_cj, howmuchagreements from clients;
c_id clients.id_c%type;
c_faktura clients.faktura_suma_cj%type;
c_howmuch clients.howmuchagreements%type;
CURSOR c_products is
select id_p, unit_duration_calculation from products;
p_id products.id_p%type;
p_durat products.unit_duration_calculation%type;
CURSOR c_transactions is
Select id_t, id_c, id_p, ud_c, procent_alokacji from transactions;
t_id_t transactions.id_t%type;
t_id_c transactions.id_c%type;
t_id_p transactions.id_p%type;
t_ud_c transactions.ud_c%type;
t_procent transactions.procent_alokacji%type;
counter_clients number:=1;
sum_products number:=1;
BEGIN
open c_clients;
open c_products;
open c_transactions;
fetch c_clients into c_id, c_faktura, c_howmuch;
fetch c_products into p_id, p_durat;
FOR i in 1 .. totalTransactions() loop
fetch c_transactions into t_id_t, t_id_c, t_id_p,t_ud_c, t_procent;
if counter_clients!=t_id_c Then
counter_clients:= counter_clients+1;
fetch c_clients into c_id, c_faktura, c_howmuch;
end if;
t_procent:=t_ud_c/c_faktura;
end loop;
END;
解决方案
如果我正确理解您的问题,您想TRANSACTIONS
使用计算值更新表格t_procent
。我相信您想在计算后添加以下语句t_procent
:
UPDATE TRANSACTIONS
SET PROCENT_ALOKACJI = t_procent
WHERE ID_T = t_id_t;
如果没有对表的完整描述,TRANSACTIONS
我无法确定,但它似乎TRANSACTIONS.ID_T
可能是TRANSACTION
表上的主键。如果这不正确,请随意替换正确的一列或多列。
祝你好运。
推荐阅读
- android - 在Android中检测空的PagedList结果
- python - tkinter 按钮多次打印相同的东西
- python - 如何使用 AvroProducer 向主题添加数据
- python - python 制作的下拉菜单可以在 HTML/CSS 中编辑吗?
- python - 搜索一种将数据插入到excel模板并用python保存的方法
- r - 在 r weave 中编译 pdf 时出现此错误
- python - 如何从python中的不同目录导入模块
- asynchronous - Rabbit MQ - 消息顺序优先消费
- ssl - 捆绑的 SSL 证书公钥与私钥公钥不匹配
- java - 密码如何必须包含至少八个字符,至少一个数字以及小写和特殊字符?