派生列的值我有两个表创建触发器从另一个表
Items
ITEM_CODE VARCHAR2(20)
ITEM_NAME VARCHAR2(20)
PRICE_TON NUMBER(38,5)
PRICE_REAM NUMBER(38,5)
PRICE_SHEET NUMBER(38,5)
Orderitems
ORDER_ITEMS_CODE VARCHAR2(20)
ORDER_CODE VARCHAR2(20)
ITEM_CODE_ORDERS VARCHAR2(20)
ORDER_QUANTITY NUMBER(4,0)
ORDER_UNIT VARCHAR2(5)
UNIT_PRICE NUMBER(38,5)
我想根据order_unit 我想这个触发器创建触发器来计算UNIT_PRICE,但它没有工作
create or replace TRIGGER "Orderitems_T1"
BEFORE
insert or update on orderitems
for each row
begin
declare
order_unit orderitems.order_unit%type;
unit_price orderitems.unit_price%type;
price_sheet Items.price_sheet%type;
price_ream Items.price_ream%type;
price_ton Items.price_ton%type;
item_code Items.item_code%type;
item_code_orders orderitems.item_code_orders%type;
when item_code_orders = item_code then
begin
case
when order_unit ='sheet' then unit_price := price_sheet;
when order_unit = 'ton' then unit_price := price_ton ;
when order_unit = 'ream' then unit_price := price_ream ;
else unit_price := 0;
end case;
end;
end;
我收到此错误
PLS-00103:出现符号“何时”在需要下列之一时:开始功能编译程序亚型典型值e当前光标删除先前存在
PLS-00103:遇到符号“;”当期待以下情况之一时:情况符号“case”被替换为“;”接着说。
您指定的WHEN子句位置不正确,但更重要的是您命名ORDERITEMS表中存在的一个字段(ITEM_CODE_ORDERS)和存在于ITEMS表中的另一个字段(ITEM_CODE)。在WHEN子句中命名的所有字段必须存在于触发器操作的表中(在本例中为ORDERITEMS表)。请编辑您的问题并解释更多关于您想要完成的内容。谢谢。 –
我想计算表ORDERITEMS中插入的每个项目的unit_price ,,如果(item_code)时(ITEMS表)中的(order_unit)等于'ton',那么(unit_price)等于(Price_ton)时,此(unit_price)取决于order_unit。在ORDERITEMS – user2648669