Skip to Main Content
  • Questions
  • How to create a trigger for a table and multiply the values inserted into the table by a function.

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Ridheen.

Asked: December 14, 2017 - 1:52 pm UTC

Last updated: December 15, 2017 - 7:05 am UTC

Version: oracle 12c

Viewed 1000+ times

You Asked

Dear Tom

My requirement is..


I need to create a trigger for a empty table, where the data will be inserted into the columns.

i need to multiply the inserting values by a function which is already created and the result should be stored into the another column of same table or the same column of same table.

the trigger should do this activity.

Kindly do the need full.

Send mail if possible : ridheen.sudevan@niyuj.com

and Connor said...

Sounds like student homework to me ... but since its christmas :-)

SQL> create table t ( x int, y int );

Table created.

SQL>
SQL> create or replace function f(p_in number) return number is
  2  begin
  3    return p_in*2;
  4  end;
  5  /

Function created.

SQL>
SQL>
SQL> create or replace
  2  trigger trg
  3  before insert on t
  4  for each row
  5  begin
  6    :new.y := f(:new.x);
  7  end;
  8  /

Trigger created.

SQL> insert into t(x) values (1);

1 row created.

SQL> select * from t;

         X          Y
---------- ----------
         1          2




Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library