简体   繁体   中英

what is wrong with this trigger unable to insert into trigger table?

CREATE OR REPLACE FUNCTION insert_data_into_stock_ledger_for_opstock()
  RETURNS trigger AS
$BODY$
 DECLARE
    stocid integer;
    rec1 record;
 BEGIN
    FOR rec1 IN
    select * from mas_stock
    where stock_id = NEW.stock_id
    LOOP
        INSERT into stock_leger_head (tra_id,tra_type,date,dept_id,flag,item_id,qty) values (NEW.stock_id,'OS',NEW.created_datetime,NEW.dept_id,'I',rec1.item_id,rec1.qty) RETURNING stock_id INTO stocid;
        /*IF rec1.model_no IS NULL OR rec1.model_no = ''
        THEN
            RETURN NEW;
        ELSE*/
            INSERT into stock_leger_detail (stock_id,model_no,serial_batch,qty) values (stocid,rec1.model_no,rec1.serial_batch_no,rec1.qty);
        /*END IF; */
    END LOOP;
    RETURN NEW;
 END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION insert_data_into_stock_ledger_for_opstock()
  OWNER TO postgres;

This is the First time i am using triggers i dont know what is going wrong .not even showing any error while insert also.Data insert into mas_stock working fine but not triggering ??

must be added :

 CREATE TRIGGER (TRIGGER_NAME) before delete on (NAME_TABLE)
FOR EACH ROW EXECUTE PROCEDURE insert_data_into_stock_ledger_for_opstock();

在每个行执行程序上在mas_stock上插入后创建触发器insert_opening_stock; insert_data_into_stock_ledger_for_opstock();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM