database-trigger

didn't send mail html body in plsql

好久不见. 提交于 2019-12-02 19:04:21
问题 I developed a trigger in plsql, the trigger work but I received 6 mails in the same time. I need just one mail, how I can do it? CREATE or replace TRIGGER RI AFTER insert or update on ap_supplier_sites_all for each row DECLARE x_count NUMBER; begin select count(*) into x_count from rib1 r1,rib2 r2 where r1.ATTRIBUTE4=r2.Supplier_RIB; if(x_count > 0) then testrib;--execute SP end if; end; 回答1: Here's how it goes: trigger fires when you insert or update rows in AP_SUPPLIER_SITES_ALL suppose you

sql triggers I have error while storing column name in variable and use it for OLD.myvar in sql triggers

耗尽温柔 提交于 2019-12-02 11:53:25
MySQL said: #1054 - Unknown column 'TMPCOL' in 'OLD' BEGIN DECLARE TOTAL,I INT; DECLARE CURRENT_CLOUMN VARCHAR(255); DECLARE TRIGGER_ON_TABLE VARCHAR(255); DECLARE TRIGGER_OP VARCHAR(255); DECLARE olddd VARCHAR(255); DECLARE newwww VARCHAR(255); SET TOTAL=0; SET I=0; SET CURRENT_CLOUMN='atulbaldaniya.com'; SET TRIGGER_ON_TABLE='atulbaldaniya'; SET TRIGGER_OP='UPDATE'; SET olddd=''; SET newwww=''; SELECT COUNT(COLUMN_NAME) INTO TOTAL FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = TRIGGER_ON_TABLE ORDER BY ORDINAL_POSITION; WHILE I < TOTAL DO SELECT COLUMN_NAME INTO CURRENT_CLOUMN FROM

Oracle PL/SQL: Loop Over Trigger Columns Dynamically

自闭症网瘾萝莉.ら 提交于 2019-12-01 19:34:17
问题 Inside of a trigger I'm trying to loop over all columns on a table and compare the new values to the old values. Here is what I have so far: CREATE OR REPLACE TRIGGER "JOSH".TEST#UPD BEFORE UPDATE ON "JOSH"."TEST_TRIGGER_TABLE" REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW declare oldval varchar(2000); newval varchar(2000); begin for row in (SELECT column_name from user_tab_columns where table_name='TEST_TRIGGER_TABLE') loop execute immediate 'select :old.'||row.column_name||' from dual'

Is it possible to dynamically loop through a table's columns?

天大地大妈咪最大 提交于 2019-12-01 06:19:31
I have a trigger function for a table test which has the following code snippet: IF TG_OP='UPDATE' THEN IF OLD.locked > 0 AND ( OLD.org_id <> NEW.org_id OR OLD.document_code <> NEW.document_code OR -- other columns ... ) THEN RAISE EXCEPTION 'Message'; -- more code So I am statically checking all the column's new value with its previous value to ensure integrity. Now every time my business logic changes and I have to add new columns into that table, I will have to modify this trigger each time. I thought it would be better if somehow I could dynamically check all the columns of that table,

Is it possible to dynamically loop through a table's columns?

孤街醉人 提交于 2019-12-01 03:07:56
问题 I have a trigger function for a table test which has the following code snippet: IF TG_OP='UPDATE' THEN IF OLD.locked > 0 AND ( OLD.org_id <> NEW.org_id OR OLD.document_code <> NEW.document_code OR -- other columns ... ) THEN RAISE EXCEPTION 'Message'; -- more code So I am statically checking all the column's new value with its previous value to ensure integrity. Now every time my business logic changes and I have to add new columns into that table, I will have to modify this trigger each

SQLite: How to limit the number of rows based on the timestamp?

人走茶凉 提交于 2019-12-01 00:21:31
I successfully used the following BEFORE INSERT trigger to limit the number of rows stored in the SQLite database table locations . The database table acts as a cache in an Android application. CREATE TRIGGER 'trigger_locations_insert' BEFORE INSERT ON 'locations' WHEN ( SELECT count(*) FROM 'locations' ) > '100' BEGIN DELETE FROM 'locations' WHERE '_id' NOT IN ( SELECT '_id' FROM 'locations' ORDER BY 'modified_at' DESC LIMIT '100' ); END Meanwhile, I added a second trigger that allows me to INSERT OR UPDATE rows. - The discussion on that topic can be found in another thread . The second

SQLite: How to limit the number of rows based on the timestamp?

≯℡__Kan透↙ 提交于 2019-11-30 18:48:14
问题 I successfully used the following BEFORE INSERT trigger to limit the number of rows stored in the SQLite database table locations . The database table acts as a cache in an Android application. CREATE TRIGGER 'trigger_locations_insert' BEFORE INSERT ON 'locations' WHEN ( SELECT count(*) FROM 'locations' ) > '100' BEGIN DELETE FROM 'locations' WHERE '_id' NOT IN ( SELECT '_id' FROM 'locations' ORDER BY 'modified_at' DESC LIMIT '100' ); END Meanwhile, I added a second trigger that allows me to

How to disable triggers in MySQL?

六眼飞鱼酱① 提交于 2019-11-28 21:21:26
In my MySQL database I have some triggers ON DELETE and ON INSERT . Sometimes I need to disable some triggers, and I have to DROP e.g. DROP TRIGGER IF EXISTS hostgroup_before_insert // and reinstall. Is there any shortcut to SET triggers hostgroup_before_insert = 0 like we have for foreign keys: mysql> SELECT version(); +-------------------------+ | version() | +-------------------------+ | 5.1.61-0ubuntu0.10.10.1 | +-------------------------+ 1 row in set (0.00 sec) EDIT Answer There is no built-in server system variable TRIGGER_CHECKS in MySQL . A simple workaround is to instead use a user

MySQL trigger set values for NEW row and update another in the same table

大兔子大兔子 提交于 2019-11-27 14:07:56
I have a table that I keep track of fees for a specific item. These fees can change over time so I have two columns (startDate, endDate) with the current set of fees always having an endDate in the far future. I already have a trigger that I use to do some calculations on the new row being entered but what I also want to have happen is if I enter an item that already has an entry I want to set the previous entry's endDate to the day before the new entry's startDate and the new endDate to a predetermined far-away date. Here is the code for what I tried first: CREATE DEFINER=`root`@`%` TRIGGER

Create trigger error: invalid syntax

混江龙づ霸主 提交于 2019-11-26 22:07:51
问题 SQL query: CREATE TRIGGER tg_newuser_insert BEFORE INSERT ON tbl_newuser FOR EACH ROW BEGIN INSERT INTO tbl_seq VALUES (NULL) SET NEW.id = CONCAT('YTUM', LPAD(LAST_INSERT_ID(), 8, '00000')); END MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET NEW.id = CONCAT('YTUM', LPAD(LAST_INSERT_ID(), 8, '00000')); END' at line 6 回答1: Your Formatting is off, remember DELIMITER $$