[范例]怎樣判斷畫布中有重復記錄(Forms 6i)
2024-07-21 02:35:54
供稿:網友
最完美的解決方法:自己編寫代碼,可以產生精確的報錯信息,及檢查出新輸入數據內的重復問題。
由于when-validate-item 不能使用go_item(),first_record等,而when-new-item-instance卻答應,所以,可以這樣處理:
以基本表(id主鍵,name ,remark,20行每頁界面)
在id(主鍵)的下一導航項,設置為check_uniqueness_button.
check_uniqueness_button為這個塊內的一個按鈕,它的when-new-item-instance擔任檢查該行的重復情況的功能,代碼見本貼附錄。
另外,手工按check_uniqueness_button,也會執行這段代碼,產生手工檢查重復情況的功能。
附錄代碼:
declare
temPRecord number;
tempval varchar2(20);
temp_count number :=0;
BEGIN
go_item('base_table.id');
temprecord := :system.cursor_record;
tempval := :base_table.id;
first_record;
if :system.current_value is not null then ---假如有記錄,開始運算
loop
if :base_table.id = tempval and :system.cursor_record <> temprecord then
temp_count := temp_count + 1;
message('代碼有重復,請檢查第:' :system.cursor_record
'行,代碼:' :base_table.id ',名稱:' :base_table.name);
message('代碼有重復,請檢查第:' :system.cursor_record
'行,代碼:' :base_table.id ',名稱:' :base_table.name);
end if;
next_record;
if :system.current_value is null then
exit;
end if;
end loop;
if temp_count = 0 then
message('該行代碼沒有重復');
end if;
go_record(temprecord);
go_item('base_table.name');
else
message('光標所有行沒有代碼為空,請先將光標放在有數值的地方');
message('光標所有行沒有代碼為空,請先將光標放在有數值的地方');
end if;
END;
附錄
check_record_uniqueness 可以檢查一個數據塊(Data Block)內,主鍵有無重復的記錄。
使用方法舉例:
1.Block 上,先設定一個item是主鍵。
2。在主鍵字段的 when-validate-item trigger 上,加入如下代碼:
check_record_uniqueness;
if not form_sUCess then
clear message;
message(數據有重復!");
end if;
以上代碼,可以使用戶每輸入一條記錄時,系統自動檢查主鍵有無重復。
優點:速度快,代碼簡單。
缺點:只能應用于主鍵。
最致命的缺點:經測試后我發現,它只能檢查新輸入的數據,與已存盤的數據有無重復。假如新輸入的記錄與未存盤的記錄重復,它不會報警!
使用建議:
1。只可用于比較簡單的場合,及用戶每次輸入的資料數目比較少的情況。假如用戶大批量輸入:如每次輸入幾十條,甚至上百條,使用check_record_uniqueness便會心驚膽跳了,因為誰也不能保證 ,新輸入的數據內會否有重復。
2。假如不是應用于主鍵,假如每次用戶輸入量可能比較大,建議自行編寫查重復的代碼。
---本文為原創,
by armok.