Home > Mobile >  PL/SQL cursor and trigger
PL/SQL cursor and trigger

Time:06-28

I'm totally new to triggers and cursors and I have the following task:

The first (i guess easier) part of the task: I have to create a table (Table Sum) then I have to fill it up with data with the help of a cursor. The table has 3 columns (Currency, Type, Sum_Price) I have another table (Table Transactions) with columns like these, however that contains price for each transaction.

The second part of the task is to create a trigger so when there comes a new record into Table Transtactions the corresponding row of Table Sum, column Sum Price has to be updated.

Could someone give me a sample code for this kind of problem? Thank you for your answer in advance!

CodePudding user response:

Here is something to get you started. In order for people to help you it would help if you provided create table statements for each table, sample data and expected output.

If you're unable to do these simple tasks perhaps you aren't the right person for this particular assignment.

CREATE TABLE table_sum (currency_sum, type, sum_price) AS
SELECT 55.44, 1, 123.45 FROM DUAL l UNION ALL
SELECT 6, 1, 3.55 FROM DUAL;

SELECT * FROM table_sum

CURRENCY_SUM    TYPE    SUM_PRICE
55.44    1    123.45
6    1    3.55

CodePudding user response:

You need a refernece between both tables. Then you can do something linke that:

create or replace trigger table_transaction_trg
  before insert
  on table_transaction
  for each row
begin
  update table_sum s
  set    s.sum_price = s.sum_price   :new.transaction_sum
  where  --> Here you need your reference between both tables
end;
  • Related