ORACLE訂單管理(例項

2021-04-14 05:41:24 字數 2280 閱讀 7714

create table stock

(icode varchar2(20) primary key,

idescrip varchar2(50),

pqty number(4)

);create table input

(iid varchar2(20),

icode varchar2(20),

idescrip varchar2(50),

pqty number(4),

idate date,

constraint input_pk primary key(iid,icode)

);create table sales

(sid varchar2(20),

icode varchar2(20),

idescrip varchar2(50),

pqty number(4),

sdate date,

constraint sales_pk primary key(sid,icode)

);create table return

(rid varchar2(20),

icode varchar2(20),

idescrip varchar2(50),

pqty number(4),

rdate date,

constraint return_pk primary key(rid,icode)

);3、 建立input表和sales表的觸發器,當進貨和銷售產品時,系統自動增、減stock庫存表的icode的數量。

create or replace trigger input

before insert

on input

for each row

declare

cursor c1 is select * from stock where icode=:new.icode for update;

v_stock stock%rowtype;

begin

open c1;

fetch c1 into v_stock;

if(c1%found) then

update stock set pqty=pqty+:new.pqty where current of c1;

else

insert into stock(icode,pqty,idescrip) values(:new.icode,:new.pqty,:new.idescrip);

end if;

close c1; 

end;

--測試

insert into input(iid,icode,idescrip,pqty,idate) values('001','a1','aaaaa',100,sysdate);

insert into input(iid,icode,idescrip,pqty,idate) values('005','a1','aaaaa',100,sysdate);

insert into input(iid,icode,idescrip,pqty,idate) values('003','a1','aaaaa',100,sysdate);

insert into input(iid,icode,idescrip,pqty,idate) values('004','a2','aaaaa',100,sysdate);

--insert into sales(sid,icode,idescrip,pqty,sdate) values('001','a1','aaaaa',200,sysdate);

insert into sales(sid,icode,idescrip,pqty,sdate) values('002','a1','aaaaa',200,sysdate);

insert into sales(sid,icode,idescrip,pqty,sdate) values('003','a1','aaaaa',100,sysdate);

insert into sales(sid,icode,idescrip,pqty,sdate) values('004','a1','aaaaa',100,sysdate);

insert into sales(sid,icode,idescrip,pqty,sdate) values('004','a2','aaaaa',10,sysdate);

insert into sales(sid,icode,idescrip,pqty,sdate) values('004','a1','aaaaa',10,sysdate);

oracle例項管理

oracle例項,其實就是oracle instance,在oracle資料庫體系結構中,是組成oracle伺服器的重要部分。那為什麼需要這個instance呢?專業上的一種說法是說oracle instance是用於和作業系統進行聯絡的標識,也就是資料庫和作業系統之間的互動使用的是資料庫例項。換句...

生產訂單BADI例項

以生產訂單收貨為例 1 badi的查詢方法 se38在程式中搜尋關鍵字cl exithandler 或se24 cl exithandler 在方法get instance中打斷點,然後執行相應事物碼撲捉badi 然後執行mb31事務碼 假若找到可以使用的badi為mb document badi。...

訂單管理業務層

訂單處理服務 service public class orderserviceimpl implements orderservice private string order id gen key value private string order id start value private...