|
|
发表于 2008/11/20 09:22:41
|
显示全部楼层
给个例子你吧。俺写过一个,看下面
CREATE OR REPLACE TRIGGER xxpo_lines_all_t2
BEFORE INSERT OR UPDATE
ON po_lines_all
FOR EACH ROW
WHEN (NEW.item_id IS NOT NULL)
DECLARE
ln_exists NUMBER;
ln_price NUMBER;
lv_old_price VARCHAR2 (200);
BEGIN
--Check PO type, if it is not a "BLK" or "STD PO", then return.
BEGIN
SELECT 1
INTO ln_exists
FROM po_headers_all pha
WHERE pha.type_lookup_code IN ('BLANKET', 'STANDARD')
AND pha.po_header_id = :NEW.po_header_id;
EXCEPTION
WHEN OTHERS
THEN
ln_exists := 0;
END;
IF ln_exists = 1
THEN
--Change list price to master inventory organization's purchars list price.
IF INSERTING
THEN
BEGIN
SELECT msi.list_price_per_unit
INTO ln_price
FROM mtl_system_items_b msi
WHERE msi.inventory_item_id = :NEW.item_id
--As per BSR A001255, modified by Jojo jz zhu 2008-11-17.
--AND msi.organization_id = 45;
AND msi.organization_id = NVL ((SELECT inventory_organization_id
FROM financials_system_params_all fsp
WHERE fsp.org_id = :NEW.org_id), 45);
--As per BSR A001255, end modified by Jojo jz zhu 2008-11-17.
EXCEPTION
WHEN NO_DATA_FOUND
THEN
Po_Message_S.sql_error ('PO'
, 'Can not found PO line '
|| :NEW.line_num
|| '''s inventory item in Master Organization!'
, -20001);
App_Exception.raise_exception;
END;
:NEW.list_price_per_unit := ln_price;
END IF;
--Check new list price and old list price when update.
IF UPDATING
AND ( ( :NEW.list_price_per_unit IS NULL
AND :OLD.list_price_per_unit IS NOT NULL)
OR ( :NEW.list_price_per_unit IS NOT NULL
AND :OLD.list_price_per_unit IS NULL)
OR (:NEW.list_price_per_unit <> :OLD.list_price_per_unit))
THEN
SELECT DECODE (:OLD.list_price_per_unit, NULL, 'NULL', :OLD.list_price_per_unit)
INTO lv_old_price
FROM DUAL;
Po_Message_S.sql_error ('PO'
, ' Can not update PO line '
|| :NEW.line_num
|| '''s List Price! '
|| CHR (10)
|| 'Please change List Price back to old value: '
|| lv_old_price
, -20001);
App_Exception.raise_exception;
END IF;
END IF;
END;
/ |
|