首页 > 解决方案 > 如何将逐行值更新到表 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;

标签: sqloracleplsql

解决方案


如果我正确理解您的问题,您想TRANSACTIONS使用计算值更新表格t_procent。我相信您想在计算后添加以下语句t_procent

UPDATE TRANSACTIONS
  SET PROCENT_ALOKACJI = t_procent
  WHERE ID_T = t_id_t;

如果没有对表的完整描述,TRANSACTIONS我无法确定,但它似乎TRANSACTIONS.ID_T可能是TRANSACTION表上的主键。如果这不正确,请随意替换正确的一列或多列。

祝你好运。


推荐阅读