{"id":2083,"date":"2016-12-08T11:01:26","date_gmt":"2016-12-08T08:01:26","guid":{"rendered":"http:\/\/www.fatihacar.com\/blog\/?p=2083"},"modified":"2016-12-08T11:17:31","modified_gmt":"2016-12-08T08:17:31","slug":"update-another-column-on-the-same-table-with-trigger-while-updating-table-in-oracle","status":"publish","type":"post","link":"https:\/\/www.fatihacar.com\/blog\/update-another-column-on-the-same-table-with-trigger-while-updating-table-in-oracle\/","title":{"rendered":"Update Another Column On The Same Table With Trigger While Updating Table in Oracle"},"content":{"rendered":"<p>If you want to do update another column when execute an update on table, you can use before update trigger. If you use after update trigger, you can get some errors. if you use pragma autonomous_transaction parameter as declare in trigger you can get errors like that are\u00a0&#8220;ORA-00060: deadlock detected while waiting for resource&#8221;, &#8220;ORA-06512: at &#8220;trigger_name&#8221; line 7&#8243;,&#8221;ORA-04088:error during execution of trigger &#8220;trigger_name&#8221;&#8221; if you don&#8217;t use, you can get errors like that are &#8220;ORA-04091: table tablename is mutating, trigger\/function may not see it&#8221;,&#8221;ORA-06512: at trigger_name&#8221;, line 6&#8243;,&#8221;ORA-04088: error during execution of trigger trigger_name&#8221;<\/p>\n<p>You can resolve this problem with using before update trigger. You can update another column of updating the same table.<\/p>\n<p><strong>Trigger Example<\/strong><\/p>\n<p>My example is about that If status column of table1 change from 0 to 1, I will write another columns that are name, surname and studentno at the same table table1.<\/p>\n<blockquote>\n<p>create table table1 (id number, status number, name varchar2(100), surname varchar2(100), studentno varchar2(100),address varchar2(500),city varchar2(100));<\/p>\n<p>create or replace trigger trg_trigger_name_upt<br \/>\nbefore update of status on table1<br \/>\nreferencing OLD as old NEW as new<br \/>\nfor each row<br \/>\nv_studentno varchar2(100);<br \/>\nbegin<\/p>\n<p>    IF :old.status = 0 AND :new.status = 1 and UPDATING THEN<\/p>\n<p>    :new.name := &#8216;Fatih&#8217;;<br \/>\n    :new.surname := &#8216;Acar&#8217;;<br \/>\n    v_studentno := seq_studentno.nextval;<br \/>\n    :new.studentno := v_studentno;<\/p>\n<p>    END IF;<\/p>\n<p>end;<br \/>\n\/\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>If you want to do update another column when execute an update on table, you can use before update trigger. If you use after update trigger, you can get some errors. if you use pragma autonomous_transaction parameter as declare in trigger you can get errors like that are\u00a0&#8220;ORA-00060: deadlock detected while waiting for resource&#8221;, &#8220;ORA-06512:&#8230;<\/p>\n","protected":false},"author":37,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[53,12,6],"tags":[32,54,103],"class_list":["post-2083","post","type-post","status-publish","format-standard","hentry","category-oracle-errors-and-solutions","category-oracle-procedure","category-oracle-sql","tag-oracle-administration","tag-oracle-error-solutions","tag-oracle-sql-query"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p39NFI-xB","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/2083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/comments?post=2083"}],"version-history":[{"count":6,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/2083\/revisions"}],"predecessor-version":[{"id":2089,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/2083\/revisions\/2089"}],"wp:attachment":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/media?parent=2083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/categories?post=2083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/tags?post=2083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}