只須要將「序號」定義成公式,並將公式設置爲:get_block_property('block_name',current_record)就能夠實現了,或者把這行語句放到「When-Create-Record」觸發器中。數據庫
缺點:增改刪時,行號不能自動刷新。app
①在須要自動行號的Block中,新增一個Item,我這裏取名爲LINE_NUM(注:這不是數據庫中的字段,即屬性Database Item爲No),放在對應畫布上及調整佈局;函數
②在對應Block添加相應Block級別的觸發器:ORDER_LINES爲個人數據塊佈局
KEY-CREREC: spa
DECLARE LINE NUMBER; BEGIN LINE := :SYSTEM.CURSOR_RECORD; LOOP IF :SYSTEM.LAST_RECORD = 'TRUE' THEN EXIT; ELSE NEXT_RECORD; :ORDER_LINES.LINE_NUM := :SYSTEM.CURSOR_RECORD + 1; END IF; END LOOP; GO_RECORD(LINE); CREATE_RECORD; :ORDER_LINES.LINE_NUM := :SYSTEM.CURSOR_RECORD; END;
KEY-DELREC:.net
DECLARE LINE NUMBER; BEGIN DELETE_RECORD; LINE := :SYSTEM.CURSOR_RECORD; LOOP :ORDER_LINES.LINE_NUM := :SYSTEM.CURSOR_RECORD; IF :SYSTEM.LAST_RECORD = 'TRUE' THEN EXIT; ELSE NEXT_RECORD; END IF; END LOOP; GO_RECORD(LINE); END;
WHEN-CREATE-RECORD:code
:ORDER_LINES.LINE_NUM := :SYSTEM.TRIGGER_RECORD;
POST-QUERY:(注:若是這裏使用了該觸發器,查詢會獲取不到行號,須要加入如下到該觸發器獲取行號)xml
begin :ORDER_LINES.LINE_NUM:=:SYSTEM.TRIGGER_RECORD; end;
效果圖:包含兩個數據塊(OEDER_HEADERS和ORDER_LINES),ODRDER_HEADERS.TOTAL是全部總金額,ORDER_LINES.AMOUNT是沒一行總金額blog
步驟:get
①建立ORDER_HEADERS.TOTAL,設置其子類屬性爲:TEXT_ITEM_DISPLAY_ONLY;
在合計顯示的數據塊中,建立合計項目的彙總臨時項目,命名規則爲:<合計項目名稱>_RTOT_DB,NUMBER(38)/DISPLAY_ITEM,即TOTAL_RTOT_DB/NUMBER(38)/DISPLAY_ITEM;
(注:這兩個字段都不是數據庫中的字段,故Item的屬性Database Item爲No,不然會提示該字段無效);
②添加一個包,用於封裝app_calculate.running_total()及初始化amount的存儲過程,以下:
包頭:
PACKAGE TOTAL_LINES IS procedure amount (event varchar2); procedure running_total (event varchar2); END TOTAL_LINES;
包體:
procedure running_total (event varchar2) is begin app_calculate.running_total(event,'ORDER_LINES.AMOUNT','ORDER_HEADERS.TOTAL'); end running_total; procedure amount (event varchar2) is begin if event = 'INIT' then copy(name_in('order_lines.price') * name_in('order_lines.quantity'),'order_lines.amount'); end if; end amount; END TOTAL_LINES;
③ORDER_LINES對應觸發器:(ORDER_LINES塊級,存放每行總金額的塊)
KEY-DELREC:
total_lines.running_total('KEY-DELREC'); --注:這裏是刪除行號的代碼,若是不刪除會同時刪除兩行 --DELETE_RECORD; DECLARE LINE NUMBER; BEGIN DELETE_RECORD; LINE := :SYSTEM.CURSOR_RECORD; LOOP :ORDER_LINES.LINE_NUM := :SYSTEM.CURSOR_RECORD; IF :SYSTEM.LAST_RECORD = 'TRUE' THEN EXIT; ELSE NEXT_RECORD; END IF; END LOOP; GO_RECORD(LINE); END;
KEY-DUPREC:
total_lines.running_total('KEY-DUPREC'); duplicate_record;
KEY-CLRREC:
CLEAR_RECORD;
WHEN-CLEAR-BLOCK:
total_lines.running_total('WHEN-CLEAR-BLOCK');
POST-QUERY:
total_lines.amount('INIT'); total_lines.running_total( 'POST-QUERY'); --注:這是獲取行號的 begin :ORDER_LINES.LINE_NUM:=:SYSTEM.TRIGGER_RECORD; end;
④在ORDER_HEADERS(放Total總金額的數據塊)的數據塊級觸發器上添加查詢初始化全部總金額Total
POST-QUERY:
select nvl(sum(price*quantity),0) into :order_headers.total from Cux_Order_Lines_All_25305 where header_id = :order_headers.header_id ; :order_headers.total_rtot_db:=:order_headers.total;
⑤Item級觸發器(Price和Quantity,對應修改觸發金額重新初始化)
Price和Quantity下觸發器WHEN-VALIDATE-ITEM:
total_lines.amount('INIT'); total_lines.running_total('WHEN-VALIDATE-ITEM');
這是獲取總金額的Item,須要單獨放在一個Block裏面,summrary Function屬性中是求和函數SUM,summarized Block中是所求和Item的Block,Summarized Item是所求和的Item
給每一行設置公式獲取每一行的總金額
可能會報如圖的錯,解決方式